fix(Core/Crash): Evade after cleaning threat references. (#8160)

This commit is contained in:
UltraNix
2021-10-06 06:26:03 +02:00
committed by GitHub
parent 702573038e
commit 0d411ec2c3
2 changed files with 9 additions and 2 deletions
+8 -1
View File
@@ -113,6 +113,8 @@ void HostileRefMgr::updateThreatTables()
void HostileRefMgr::deleteReferences(bool removeFromMap /*= false*/) void HostileRefMgr::deleteReferences(bool removeFromMap /*= false*/)
{ {
std::vector<Creature*> creaturesToEvade;
HostileReference* ref = getFirst(); HostileReference* ref = getFirst();
while (ref) while (ref)
{ {
@@ -127,7 +129,7 @@ void HostileRefMgr::deleteReferences(bool removeFromMap /*= false*/)
{ {
if (Creature* creature = threatMgr->GetOwner()->ToCreature()) if (Creature* creature = threatMgr->GetOwner()->ToCreature())
{ {
creature->AI()->EnterEvadeMode(); creaturesToEvade.push_back(creature);
} }
} }
} }
@@ -136,6 +138,11 @@ void HostileRefMgr::deleteReferences(bool removeFromMap /*= false*/)
delete ref; delete ref;
ref = nextRef; ref = nextRef;
} }
for (Creature* creature : creaturesToEvade)
{
creature->AI()->EnterEvadeMode();
}
} }
//================================================= //=================================================
+1 -1
View File
@@ -14812,7 +14812,7 @@ void Unit::CleanupBeforeRemoveFromMap(bool finalCleanup)
CombatStop(); CombatStop();
ClearComboPointHolders(); ClearComboPointHolders();
DeleteThreatList(); DeleteThreatList();
getHostileRefMgr().deleteReferences(true); getHostileRefMgr().deleteReferences();
GetMotionMaster()->Clear(false); // remove different non-standard movement generators. GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
} }