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:
parent
e7f2c1439c
commit
0747c2b373
3 changed files with 31 additions and 9 deletions
|
@ -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,6 +2158,8 @@ public:
|
||||||
_plan(fp),
|
_plan(fp),
|
||||||
_instance(ins)
|
_instance(ins)
|
||||||
{
|
{
|
||||||
|
assert(fp);
|
||||||
|
assert(sys);
|
||||||
_gcSaveKey = _nasal->gcSave(ins);
|
_gcSaveKey = _nasal->gcSave(ins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
return naCallMethod(code, self, argc, args, locals);
|
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)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
return naCallMethodCtx(ctx, code, self, argc, args, locals);
|
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,17 +1200,24 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FGNasalSys::logNasalStack(naContext context)
|
||||||
|
{
|
||||||
|
const int stack_depth = naStackDepth(context);
|
||||||
if (stack_depth < 1)
|
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
|
||||||
// namespace into the global namespace under the specified module
|
// namespace into the global namespace under the specified module
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue