1
0
Fork 0

- disallow listener re-entry to prevent crash/runaway process

- move FGNasalListener function bodies to NasalSys.cxx (has become too big)
This commit is contained in:
mfranz 2006-03-20 07:13:10 +00:00
parent 101ca14a6d
commit 4c5e96f730
2 changed files with 44 additions and 17 deletions

View file

@ -674,6 +674,45 @@ naRef FGNasalSys::removeListener(int argc, naRef* args)
// FGNasalListener class.
FGNasalListener::FGNasalListener(SGPropertyNode_ptr node, naRef handler,
FGNasalSys* nasal, int key) :
_node(node),
_handler(handler),
_gcKey(key),
_nas(nasal),
_active(false)
{
}
FGNasalListener::~FGNasalListener()
{
_nas->gcRelease(_gcKey);
}
void FGNasalListener::valueChanged(SGPropertyNode* node)
{
if (_active) {
SG_LOG(SG_NASAL, SG_ALERT, "Recursive listener call "
"on property " << node->getPath());
return;
}
_active = true;
_nas->_cmdArg = node;
naContext c = naNewContext();
naModUnlock();
naCall(c, _handler, 0, 0, naNil(), naNil());
naModLock();
if(naGetError(c))
_nas->logError(c);
naFreeContext(c);
_active = false;
}
// FGNasalModelData class. If sgLoad3DModel() is called with a pointer to
// such a class, then it lets modelLoaded() run the <load> script, and the
// destructor the <unload> script. The latter happens when the model branch

View file

@ -126,23 +126,10 @@ private:
class FGNasalListener : public SGPropertyChangeListener {
public:
FGNasalListener(SGPropertyNode_ptr node, naRef handler,
FGNasalSys* nasal, int key)
: _node(node), _handler(handler), _gcKey(key), _nas(nasal) {}
FGNasalSys* nasal, int key);
~FGNasalListener() {
_nas->gcRelease(_gcKey);
}
void valueChanged(SGPropertyNode* node) {
_nas->_cmdArg = node;
naContext c = naNewContext();
naModUnlock();
naCall(c, _handler, 0, 0, naNil(), naNil());
naModLock();
if(naGetError(c))
_nas->logError(c);
naFreeContext(c);
}
~FGNasalListener();
void valueChanged(SGPropertyNode* node);
private:
friend class FGNasalSys;
@ -150,6 +137,7 @@ private:
naRef _handler;
int _gcKey;
FGNasalSys* _nas;
bool _active;
};
@ -161,7 +149,7 @@ public:
private:
string _module;
SGPropertyNode_ptr _unload;
SGConstPropertyNode_ptr _unload;
};
#endif // __NASALSYS_HXX