From f0996fa47d43346c7b88cf833ae24c6a98235981 Mon Sep 17 00:00:00 2001 From: mfranz Date: Thu, 26 Jan 2006 00:18:27 +0000 Subject: [PATCH] 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 --- src/Scripting/NasalSys.cxx | 3 ++- src/Scripting/NasalSys.hxx | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 4bbe08295..6b30376e3 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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 diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index 1a1423bc6..41e3d96ef 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -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; };