]> git.mxchange.org Git - flightgear.git/commitdiff
- don't allow removal of active listener (prevents crash)
authormfranz <mfranz>
Wed, 17 Jan 2007 13:56:22 +0000 (13:56 +0000)
committermfranz <mfranz>
Wed, 17 Jan 2007 13:56:22 +0000 (13:56 +0000)
- error message if removelistener() is called with invalid or no id

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

index 5043dc0f0f4a7dade07ccb6348304d25ed545893..8e254f5ff551e93c98c04315e54943b6acacfde6 100644 (file)
@@ -285,7 +285,7 @@ static naRef f_setlistener(naContext c, naRef me, int argc, naRef* args)
 static naRef f_removelistener(naContext c, naRef me, int argc, naRef* args)
 {
     FGNasalSys* nasal = (FGNasalSys*)globals->get_subsystem("nasal");
-    return nasal->removeListener(argc, args);
+    return nasal->removeListener(c, argc, args);
 }
 
 // Returns a ghost handle to the argument to the currently executing
@@ -681,17 +681,22 @@ naRef FGNasalSys::setListener(int argc, naRef* args)
 
 // removelistener(int) extension function. The argument is the id of
 // a listener as returned by the setlistener() function.
-naRef FGNasalSys::removeListener(int argc, naRef* args)
+naRef FGNasalSys::removeListener(naContext c, int argc, naRef* args)
 {
     naRef id = argc > 0 ? args[0] : naNil();
-    if(!naIsNum(id))
-        return naNil();
-
     int i = int(id.num);
-    if (_listener.find(i) == _listener.end())
+
+    if(!naIsNum(id) || _listener.find(i) == _listener.end()) {
+        naRuntimeError(c, "removelistener() with invalid listener id");
         return naNil();
+    }
 
     FGNasalListener *nl = _listener[i];
+    if(nl->_active) {
+        naRuntimeError(c, "trying to remove active listener");
+        return naNil();
+    }
+
     _listener.erase(i);
     delete nl;
     return naNum(_listener.size());
index 5e9b197d1991649a014591de608d4969ea9a6a21..f8a93dd2552fe9c0841c5de18580cb8eb18e6909 100644 (file)
@@ -44,7 +44,7 @@ public:
 
     // Implementation of the setlistener extension function
     naRef setListener(int argc, naRef* args);
-    naRef removeListener(int argc, naRef* args);
+    naRef removeListener(naContext c, int argc, naRef* args);
 
     // Returns a ghost wrapper for the current _cmdArg
     naRef cmdArgGhost();