1
0
Fork 0

Fix for a flight-plan / delegate crash

Catch a specific issue (-1 index not permitted for fp.current in Nasal),
but also catch
This commit is contained in:
James Turner 2018-09-07 15:17:55 +01:00
parent e7f2c1439c
commit 0747c2b373
3 changed files with 31 additions and 9 deletions

View file

@ -718,8 +718,8 @@ static void flightplanGhostSetMember(naContext c, void* g, naRef field, naRef va
fp->setIdent(naStr_data(value)); fp->setIdent(naStr_data(value));
} else if (!strcmp(fieldName, "current")) { } else if (!strcmp(fieldName, "current")) {
int index = static_cast<int>(value.num); int index = static_cast<int>(value.num);
if ((index < 0) || (index >= fp->numLegs())) { if ((index < -1) || (index >= fp->numLegs())) {
return; naRuntimeError(c, "flightplan.current must be a valid index or -1");
} }
fp->setCurrentIndex(index); fp->setCurrentIndex(index);
} else if (!strcmp(fieldName, "departure")) { } else if (!strcmp(fieldName, "departure")) {
@ -2158,7 +2158,9 @@ public:
_plan(fp), _plan(fp),
_instance(ins) _instance(ins)
{ {
_gcSaveKey = _nasal->gcSave(ins); assert(fp);
assert(sys);
_gcSaveKey = _nasal->gcSave(ins);
} }
~NasalFPDelegate() override ~NasalFPDelegate() override

View file

@ -283,12 +283,23 @@ naRef FGNasalSys::callWithContext(naContext ctx, naRef code, int argc, naRef* ar
naRef FGNasalSys::callMethod(naRef code, naRef self, int argc, naRef* args, naRef locals) naRef FGNasalSys::callMethod(naRef code, naRef self, int argc, naRef* args, naRef locals)
{ {
return naCallMethod(code, self, argc, args, locals); try {
return naCallMethod(code, self, argc, args, locals);
} catch (sg_exception& e) {
SG_LOG(SG_NASAL, SG_DEV_ALERT, "caught exception invoking nasal method:" << e.what());
return naNil();
}
} }
naRef FGNasalSys::callMethodWithContext(naContext ctx, naRef code, naRef self, int argc, naRef* args, naRef locals) naRef FGNasalSys::callMethodWithContext(naContext ctx, naRef code, naRef self, int argc, naRef* args, naRef locals)
{ {
return naCallMethodCtx(ctx, code, self, argc, args, locals); try {
return naCallMethodCtx(ctx, code, self, argc, args, locals);
} catch (sg_exception& e) {
SG_LOG(SG_NASAL, SG_DEV_ALERT, "caught exception invoking nasal method:" << e.what());
logNasalStack(ctx);
return naNil();
}
} }
FGNasalSys::~FGNasalSys() FGNasalSys::~FGNasalSys()
@ -296,7 +307,7 @@ FGNasalSys::~FGNasalSys()
if (_inited) { if (_inited) {
SG_LOG(SG_GENERAL, SG_ALERT, "Nasal was not shutdown"); SG_LOG(SG_GENERAL, SG_ALERT, "Nasal was not shutdown");
} }
nasalSys = 0; nasalSys = nullptr;
} }
bool FGNasalSys::parseAndRunWithOutput(const std::string& source, std::string& output, std::string& errors) bool FGNasalSys::parseAndRunWithOutput(const std::string& source, std::string& output, std::string& errors)
@ -1189,16 +1200,23 @@ void FGNasalSys::loadPropertyScripts(SGPropertyNode* n)
void FGNasalSys::logError(naContext context) void FGNasalSys::logError(naContext context)
{ {
SG_LOG(SG_NASAL, SG_ALERT, "Nasal runtime error: " << naGetError(context)); SG_LOG(SG_NASAL, SG_ALERT, "Nasal runtime error: " << naGetError(context));
int stack_depth = naStackDepth(context); logNasalStack(context);
if( stack_depth < 1 ) }
void FGNasalSys::logNasalStack(naContext context)
{
const int stack_depth = naStackDepth(context);
if (stack_depth < 1)
return; return;
SG_LOG(SG_NASAL, SG_ALERT, SG_LOG(SG_NASAL, SG_ALERT,
" at " << naStr_data(naGetSourceFile(context, 0)) << " at " << naStr_data(naGetSourceFile(context, 0)) <<
", line " << naGetLine(context, 0)); ", line " << naGetLine(context, 0));
for(int i=1; i<stack_depth; i++) for(int i=1; i<stack_depth; i++) {
SG_LOG(SG_NASAL, SG_ALERT, SG_LOG(SG_NASAL, SG_ALERT,
" called from: " << naStr_data(naGetSourceFile(context, i)) << " called from: " << naStr_data(naGetSourceFile(context, i)) <<
", line " << naGetLine(context, i)); ", line " << naGetLine(context, i));
}
} }
// Reads a script file, executes it, and places the resulting // Reads a script file, executes it, and places the resulting

View file

@ -217,6 +217,8 @@ private:
void addPersistentTimer(TimerObj* pto); void addPersistentTimer(TimerObj* pto);
void removePersistentTimer(TimerObj* obj); void removePersistentTimer(TimerObj* obj);
static void logNasalStack(naContext context);
}; };
#if 0 #if 0