X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fevent_mgr.cxx;h=503bd974e7f9c551604c958787e5d191a9b09d0a;hb=f41b18f0649a50e179ba41383f4061e1878c4d4c;hp=37ef4e13bdc18d5082d77e4a95e97b80d1a18d8a;hpb=dd613d48bcd84eb569813a9b946ab2c284527424;p=simgear.git diff --git a/simgear/structure/event_mgr.cxx b/simgear/structure/event_mgr.cxx index 37ef4e13..503bd974 100644 --- a/simgear/structure/event_mgr.cxx +++ b/simgear/structure/event_mgr.cxx @@ -38,7 +38,8 @@ void SGTimer::run() (*callback)(); } -SGEventMgr::SGEventMgr() +SGEventMgr::SGEventMgr() : + _inited(false) { } @@ -54,6 +55,22 @@ void SGEventMgr::unbind() _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); @@ -64,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); @@ -97,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; } } @@ -105,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)