Skip to content

Commit

Permalink
fix crash on updateTargetList
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Oct 11, 2023
1 parent 73827db commit e4320e1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,16 @@ void Monster::updateTargetList() {

auto targetIterator = targetIDList.begin();
while (targetIterator != targetIDList.end()) {
auto creature = targetListMap[*targetIterator].lock();
const uint32_t targetId = *targetIterator;

auto creature = targetListMap[targetId].lock();
if (!creature || creature->getHealth() <= 0 || !canSee(creature->getPosition())) {
targetIterator = targetIDList.erase(targetIterator);
targetListMap.erase(*targetIterator);

auto itTLM = targetListMap.find(targetId);
if (itTLM != targetListMap.end()) {
targetListMap.erase(itTLM);
}
} else {
++targetIterator;
}
Expand Down

0 comments on commit e4320e1

Please sign in to comment.