1
0
Fork 0

create a new context for listener functions to avoid context corruption

(caused a crash when a timer triggered a listener) ... Idea and OK by Andy
This commit is contained in:
mfranz 2006-01-26 00:18:27 +00:00
parent 62607b3376
commit f0996fa47d
2 changed files with 8 additions and 6 deletions

View file

@ -617,7 +617,8 @@ void FGNasalSys::setListener(int argc, naRef* args)
if(!(naIsCode(handler) || naIsCCode(handler) || naIsFunc(handler)))
return;
node->addChangeListener(new FGNasalListener(handler, this, gcSave(handler)));
gcSave(handler);
node->addChangeListener(new FGNasalListener(handler, this));
}
// functions providing access to the NasalDisplay - used to display text directly on the screen

View file

@ -112,20 +112,21 @@ private:
class FGNasalListener : public SGPropertyChangeListener {
public:
FGNasalListener(naRef handler, FGNasalSys* nasal, int gcKey)
: _handler(handler), _gcKey(gcKey), _nas(nasal) {}
FGNasalListener(naRef handler, FGNasalSys* nasal)
: _handler(handler), _nas(nasal) {}
void valueChanged(SGPropertyNode* node) {
_nas->_cmdArg = node;
naCall(_nas->_context, _handler, 0, 0, naNil(), naNil());
if(naGetError(_nas->_context))
naContext subc = naNewContext();
naCall(subc, _handler, 0, 0, naNil(), naNil());
if(naGetError(subc))
_nas->logError();
naFreeContext(subc);
}
private:
friend class FGNasalSys;
naRef _handler;
int _gcKey;
FGNasalSys* _nas;
};