]> git.mxchange.org Git - flightgear.git/commitdiff
- disallow listener re-entry to prevent crash/runaway process
authormfranz <mfranz>
Mon, 20 Mar 2006 07:13:10 +0000 (07:13 +0000)
committermfranz <mfranz>
Mon, 20 Mar 2006 07:13:10 +0000 (07:13 +0000)
- move FGNasalListener function bodies to NasalSys.cxx (has become too big)

src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index 4f3d1f36acf3fb6ef65e2e88bb016200039d5bd9..17187e9b39b755ccdab13d894558f13ef450c0b4 100644 (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
index 8319ea17f9e9140255e2c51f88be02f566c668d9..0b10ad0c7f20e191dd5bdeb90587ee0a33c3d5a0 100644 (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