diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 9c79b9420..9e4a75ad1 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -433,12 +433,14 @@ void FGNasalSys::update(double) { if(_purgeListeners) { _purgeListeners = false; - map::iterator it, end = _listener.end(); - for(it = _listener.end(); --it != end;) { + map::iterator it; + for(it = _listener.end(); it != _listener.end();) { FGNasalListener *nl = it->second; if(nl->_dead) { - _listener.erase(it); + _listener.erase(it--); delete nl; + } else { + --it; } } }