Skip to content

Commit

Permalink
fix: possible crash in creatureevents (#2622)
Browse files Browse the repository at this point in the history
Changes Proposed
- Fixed broken iteration.

Issues addressed:
- Crash because removing element from map and iterating.

Co-authored-by: Eduardo Dantas <eduardo.dantas@hotmail.com.br>
  • Loading branch information
luanluciano93 and dudantas committed May 12, 2024
1 parent fa2bf6f commit 5aeb64c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/lua/creature/creatureevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,9 @@ CreatureEvent::CreatureEvent(LuaScriptInterface* interface) :
Script(interface) { }

void CreatureEvents::removeInvalidEvents() {
for (auto it = creatureEvents.begin(); it != creatureEvents.end(); ++it) {
if (it->second->getScriptId() == 0) {
creatureEvents.erase(it->second->getName());
}
}
std::erase_if(creatureEvents, [](const auto &pair) {
return pair.second->getScriptId() == 0;
});
}

std::string CreatureEvent::getScriptTypeName() const {
Expand Down

0 comments on commit 5aeb64c

Please sign in to comment.