X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fevent_mgr.cxx;h=503bd974e7f9c551604c958787e5d191a9b09d0a;hb=f41b18f0649a50e179ba41383f4061e1878c4d4c;hp=b855fae2db941d9e16c58dbe4ba6ab5ff7ad388b;hpb=aeb0e9aac370cb7c37e6d04b4791c9eaa4798d91;p=simgear.git diff --git a/simgear/structure/event_mgr.cxx b/simgear/structure/event_mgr.cxx index b855fae2..503bd974 100644 --- a/simgear/structure/event_mgr.cxx +++ b/simgear/structure/event_mgr.cxx @@ -38,12 +38,39 @@ void SGTimer::run() (*callback)(); } +SGEventMgr::SGEventMgr() : + _inited(false) +{ + +} + +SGEventMgr::~SGEventMgr() +{ + +} + void SGEventMgr::unbind() { _freezeProp.clear(); _rtProp.clear(); } +void SGEventMgr::init() +{ + if (_inited) { + SG_LOG(SG_GENERAL, SG_WARN, "duplicate init of SGEventMgr"); + } + _inited = true; +} + +void SGEventMgr::shutdown() +{ + _inited = false; + + _simQueue.clear(); + _rtQueue.clear(); +} + void SGEventMgr::update(double delta_time_sec) { _simQueue.update(delta_time_sec); @@ -54,6 +81,13 @@ void SGEventMgr::update(double delta_time_sec) void SGEventMgr::removeTask(const std::string& name) { + // due to the ordering of the event-mgr in FG, tasks can be removed + // after we are shutdown (and hence, have all been cleared). Guard + // against this so we don't generate warnings below. + if (!_inited) { + return; + } + SGTimer* t = _simQueue.findByName(name); if (t) { _simQueue.remove(t); @@ -87,7 +121,7 @@ SGTimerQueue::SGTimerQueue(int size) _table = new HeapEntry[_tableSize]; for(int i=0; i<_tableSize; i++) { - _table[i].pri = 0; + _table[i].pri = 0; _table[i].timer = 0; } } @@ -95,14 +129,24 @@ SGTimerQueue::SGTimerQueue(int size) SGTimerQueue::~SGTimerQueue() { + clear(); + delete[] _table; +} + +void SGTimerQueue::clear() +{ + // delete entries for(int i=0; i<_numEntries; i++) { delete _table[i].timer; - _table[i].timer = 0; } + _numEntries = 0; - delete[] _table; - _table = 0; - _tableSize = 0; + + // clear entire table to empty + for(int i=0; i<_tableSize; i++) { + _table[i].pri = 0; + _table[i].timer = 0; + } } void SGTimerQueue::update(double deltaSecs)