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:
parent
62607b3376
commit
f0996fa47d
2 changed files with 8 additions and 6 deletions
|
@ -617,7 +617,8 @@ void FGNasalSys::setListener(int argc, naRef* args)
|
||||||
if(!(naIsCode(handler) || naIsCCode(handler) || naIsFunc(handler)))
|
if(!(naIsCode(handler) || naIsCCode(handler) || naIsFunc(handler)))
|
||||||
return;
|
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
|
// functions providing access to the NasalDisplay - used to display text directly on the screen
|
||||||
|
|
|
@ -112,20 +112,21 @@ private:
|
||||||
|
|
||||||
class FGNasalListener : public SGPropertyChangeListener {
|
class FGNasalListener : public SGPropertyChangeListener {
|
||||||
public:
|
public:
|
||||||
FGNasalListener(naRef handler, FGNasalSys* nasal, int gcKey)
|
FGNasalListener(naRef handler, FGNasalSys* nasal)
|
||||||
: _handler(handler), _gcKey(gcKey), _nas(nasal) {}
|
: _handler(handler), _nas(nasal) {}
|
||||||
|
|
||||||
void valueChanged(SGPropertyNode* node) {
|
void valueChanged(SGPropertyNode* node) {
|
||||||
_nas->_cmdArg = node;
|
_nas->_cmdArg = node;
|
||||||
naCall(_nas->_context, _handler, 0, 0, naNil(), naNil());
|
naContext subc = naNewContext();
|
||||||
if(naGetError(_nas->_context))
|
naCall(subc, _handler, 0, 0, naNil(), naNil());
|
||||||
|
if(naGetError(subc))
|
||||||
_nas->logError();
|
_nas->logError();
|
||||||
|
naFreeContext(subc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class FGNasalSys;
|
friend class FGNasalSys;
|
||||||
naRef _handler;
|
naRef _handler;
|
||||||
int _gcKey;
|
|
||||||
FGNasalSys* _nas;
|
FGNasalSys* _nas;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue