- don't allow removal of active listener (prevents crash)
- error message if removelistener() is called with invalid or no id
This commit is contained in:
parent
b7a7de4f30
commit
e37b255095
2 changed files with 12 additions and 7 deletions
|
@ -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)
|
static naRef f_removelistener(naContext c, naRef me, int argc, naRef* args)
|
||||||
{
|
{
|
||||||
FGNasalSys* nasal = (FGNasalSys*)globals->get_subsystem("nasal");
|
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
|
// 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
|
// removelistener(int) extension function. The argument is the id of
|
||||||
// a listener as returned by the setlistener() function.
|
// 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();
|
naRef id = argc > 0 ? args[0] : naNil();
|
||||||
if(!naIsNum(id))
|
|
||||||
return naNil();
|
|
||||||
|
|
||||||
int i = int(id.num);
|
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();
|
return naNil();
|
||||||
|
}
|
||||||
|
|
||||||
FGNasalListener *nl = _listener[i];
|
FGNasalListener *nl = _listener[i];
|
||||||
|
if(nl->_active) {
|
||||||
|
naRuntimeError(c, "trying to remove active listener");
|
||||||
|
return naNil();
|
||||||
|
}
|
||||||
|
|
||||||
_listener.erase(i);
|
_listener.erase(i);
|
||||||
delete nl;
|
delete nl;
|
||||||
return naNum(_listener.size());
|
return naNum(_listener.size());
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
|
|
||||||
// Implementation of the setlistener extension function
|
// Implementation of the setlistener extension function
|
||||||
naRef setListener(int argc, naRef* args);
|
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
|
// Returns a ghost wrapper for the current _cmdArg
|
||||||
naRef cmdArgGhost();
|
naRef cmdArgGhost();
|
||||||
|
|
Loading…
Add table
Reference in a new issue