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));
} else if (!strcmp(fieldName, "current")) {
int index = static_cast<int>(value.num);
if ((index < 0) || (index >= fp->numLegs())) {
return;
if ((index < -1) || (index >= fp->numLegs())) {
naRuntimeError(c, "flightplan.current must be a valid index or -1");
}
fp->setCurrentIndex(index);
} else if (!strcmp(fieldName, "departure")) {
@ -2158,6 +2158,8 @@ public:
_plan(fp),
_instance(ins)
{
assert(fp);
assert(sys);
_gcSaveKey = _nasal->gcSave(ins);
}

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)
{
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)
{
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()
@ -296,7 +307,7 @@ FGNasalSys::~FGNasalSys()
if (_inited) {
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)
@ -1189,17 +1200,24 @@ void FGNasalSys::loadPropertyScripts(SGPropertyNode* n)
void FGNasalSys::logError(naContext context)
{
SG_LOG(SG_NASAL, SG_ALERT, "Nasal runtime error: " << naGetError(context));
int stack_depth = naStackDepth(context);
logNasalStack(context);
}
void FGNasalSys::logNasalStack(naContext context)
{
const int stack_depth = naStackDepth(context);
if (stack_depth < 1)
return;
SG_LOG(SG_NASAL, SG_ALERT,
" at " << naStr_data(naGetSourceFile(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,
" called from: " << naStr_data(naGetSourceFile(context, i)) <<
", line " << naGetLine(context, i));
}
}
// Reads a script file, executes it, and places the resulting
// namespace into the global namespace under the specified module

View file

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