diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index c98323a9..1d31eb8d 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -1222,13 +1222,19 @@ void Entity::UpdateXMLDoc(tinyxml2::XMLDocument* doc) { } void Entity::Update(const float deltaTime) { - for (int i = 0; i < m_Timers.size(); i++) { + int timerSize = m_Timers.size(); + for (int i = 0; i < timerSize; i++) { m_Timers[i]->Update(deltaTime); if (m_Timers[i]->GetTime() <= 0) { const auto timerName = m_Timers[i]->GetName(); - delete m_Timers[i]; - m_Timers.erase(m_Timers.begin() + i); + do { //sometimes, due to a race condition, m_Timers.erase doesn't actually erase, repeat until it does + if (m_Timers[i]->GetName() != timerName) { + break; + } + delete m_Timers[i]; + m_Timers.erase(m_Timers.begin() + i); + } while (m_Timers.size() == timerSize); //timer size indicates whether it's actually successfully been erased or not for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { script->OnTimerDone(this, timerName);