diff options
author | Naios <naios-dev@live.de> | 2016-07-03 20:52:50 +0200 |
---|---|---|
committer | Naios <naios-dev@live.de> | 2016-07-05 00:19:53 +0200 |
commit | a2ac2b3cc7a0711cf4a5d43e8c9f96b841677103 (patch) | |
tree | be107360748e4a1c69c3514af7b94015161ab99f | |
parent | 80fe552894a42b0be45fcc0fa0d55a7551e0149f (diff) |
Core/EventProcessor: Check whether an event was aborted before aborting it.
* Fixes an assertion introduced in commit 1ad73212dca0cf.
* Use itr = std::unordered_map<...>::erase for updating the iterator.
(cherry picked from commit d9755c637c39e600f145f5ecb7ff0ccf3724b1ad)
-rw-r--r-- | src/common/Utilities/EventProcessor.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/common/Utilities/EventProcessor.cpp b/src/common/Utilities/EventProcessor.cpp index 195deeb054b..2341d0a0872 100644 --- a/src/common/Utilities/EventProcessor.cpp +++ b/src/common/Utilities/EventProcessor.cpp @@ -82,24 +82,31 @@ void EventProcessor::Update(uint32 p_time) void EventProcessor::KillAllEvents(bool force) { - // first, abort all existing events - for (EventList::iterator i = m_events.begin(); i != m_events.end();) + for (auto itr = m_events.begin(); itr != m_events.end();) { - EventList::iterator i_old = i; - ++i; - - i_old->second->SetAborted(); - i_old->second->Abort(m_time); - if (force || i_old->second->IsDeletable()) + // Abort events which weren't aborted already + if (!itr->second->IsAborted()) { - delete i_old->second; + itr->second->SetAborted(); + itr->second->Abort(m_time); + } - if (!force) // need per-element cleanup - m_events.erase (i_old); + // Skip non-deletable events when we are + // not forcing the event cancellation. + if (!force && !itr->second->IsDeletable()) + { + ++itr; + continue; } + + delete itr->second; + + if (force) + ++itr; // Clear the whole container when forcing + else + itr = m_events.erase(itr); } - // fast clear event list (in force case) if (force) m_events.clear(); } |