From: mfranz Date: Wed, 8 Mar 2006 16:06:32 +0000 (+0000) Subject: crashfix: handleCommand() is called from other modules (input callbacks, X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6867462210515d94e6dbac0217a544e1f4899bae;p=flightgear.git crashfix: handleCommand() is called from other modules (input callbacks, fgcommands from C++ or GUI), so we need a separate context here. (See also solution in FGNasalListener::valueChanged) --- diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 539ac763b..2201d9b1d 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -533,12 +533,13 @@ bool FGNasalSys::handleCommand(const SGPropertyNode* arg) naRef code = parse(arg->getPath(true), nasal, strlen(nasal)); if(naIsNil(code)) return false; + naContext c = naNewContext(); naRef locals = naNil(); - if (moduleName[0]) { - naRef modname = naNewString(_context); + if(moduleName[0]) { + naRef modname = naNewString(c); naStr_fromdata(modname, (char*)moduleName, strlen(moduleName)); if(!naHash_get(_globals, modname, &locals)) - locals = naNewHash(_context); + locals = naNewHash(c); } // Cache the command argument for inspection via cmdarg(). For // performance reasons, we won't bother with it if the invoked @@ -546,10 +547,15 @@ bool FGNasalSys::handleCommand(const SGPropertyNode* arg) _cmdArg = (SGPropertyNode*)arg; // Call it! - naRef result = naCall(_context, code, 0, 0, naNil(), locals); - if(!naGetError(_context)) return true; - logError(_context); - return false; + naModUnlock(); + naRef result = naCall(c, code, 0, 0, naNil(), locals); + naModLock(); + bool error = naGetError(c); + if(error) + logError(c); + + naFreeContext(c); + return !error; } // settimer(func, dt, simtime) extension function. The first argument