SGEventMgr: Protection from timer insertion after shutdown.

This actually happens, Nasal timers are added after the event manager shutdown()
subsystem API call.
This commit is contained in:
Edward d'Auvergne
2018-03-19 14:07:11 +01:00
parent 340a469153
commit dfed2184f1
2 changed files with 11 additions and 4 deletions

View File

@@ -10,6 +10,11 @@ void SGEventMgr::add(const std::string& name, SGCallback* cb,
double interval, double delay,
bool repeat, bool simtime)
{
// Prevent Nasal from attempting to add timers after the subsystem has been
// shut down.
if (_shutdown)
return;
// Clamp the delay value to 1 usec, so that user code can use
// "zero" as a synonym for "next frame".
if(delay <= 0) delay = 1e-6;
@@ -39,14 +44,15 @@ void SGTimer::run()
}
SGEventMgr::SGEventMgr() :
_inited(false)
_inited(false),
_shutdown(false)
{
}
SGEventMgr::~SGEventMgr()
{
_shutdown = true;
}
void SGEventMgr::unbind()
@@ -69,7 +75,8 @@ void SGEventMgr::init()
void SGEventMgr::shutdown()
{
_inited = false;
_shutdown = true;
_simQueue.clear();
_rtQueue.clear();
}

View File

@@ -130,7 +130,7 @@ private:
SGPropertyNode_ptr _rtProp;
SGTimerQueue _rtQueue;
SGTimerQueue _simQueue;
bool _inited;
bool _inited, _shutdown;
};
#endif // _SG_EVENT_MGR_HXX