mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-22 13:37:22 +00:00
fix a bug with timer erasing
This commit is contained in:
parent
002f3b6c0e
commit
7bead89e39
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user