From dfed2184f1e280281277030a8a94e3e0dd7dc326 Mon Sep 17 00:00:00 2001 From: Edward d'Auvergne Date: Mon, 19 Mar 2018 14:07:11 +0100 Subject: [PATCH] SGEventMgr: Protection from timer insertion after shutdown. This actually happens, Nasal timers are added after the event manager shutdown() subsystem API call. --- simgear/structure/event_mgr.cxx | 13 ++++++++++--- simgear/structure/event_mgr.hxx | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/simgear/structure/event_mgr.cxx b/simgear/structure/event_mgr.cxx index 2e4f7b78..d5ffd01e 100644 --- a/simgear/structure/event_mgr.cxx +++ b/simgear/structure/event_mgr.cxx @@ -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(); } diff --git a/simgear/structure/event_mgr.hxx b/simgear/structure/event_mgr.hxx index 699522b8..41dc7b86 100644 --- a/simgear/structure/event_mgr.hxx +++ b/simgear/structure/event_mgr.hxx @@ -130,7 +130,7 @@ private: SGPropertyNode_ptr _rtProp; SGTimerQueue _rtQueue; SGTimerQueue _simQueue; - bool _inited; + bool _inited, _shutdown; }; #endif // _SG_EVENT_MGR_HXX