]> git.mxchange.org Git - flightgear.git/commitdiff
create a new context for listener functions to avoid context corruption
authormfranz <mfranz>
Thu, 26 Jan 2006 00:18:27 +0000 (00:18 +0000)
committermfranz <mfranz>
Thu, 26 Jan 2006 00:18:27 +0000 (00:18 +0000)
(caused a crash when a timer triggered a listener) ... Idea and OK by Andy

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

index 4bbe082958842bf1ce309034ffd3f3a9e9b40f91..6b30376e3c7ac241c921ba23363129e05156d40f 100644 (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
index 1a1423bc6950aa63a774fb88db672382339ad543..41e3d96efa018f62a70df627e51a6b99c776f087 100644 (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;
 };