From: mfranz Date: Mon, 20 Mar 2006 07:13:10 +0000 (+0000) Subject: - disallow listener re-entry to prevent crash/runaway process X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4c5e96f730ebc5c98ae247e7c3e94ebc9efaf136;p=flightgear.git - disallow listener re-entry to prevent crash/runaway process - move FGNasalListener function bodies to NasalSys.cxx (has become too big) --- diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 4f3d1f36a..17187e9b3 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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 script, and the // destructor the script. The latter happens when the model branch diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 8319ea17f..0b10ad0c7 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -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