Core/Units: protect m_Controlled unit set against removing non-existing pointers and log owner and unit to track down potential crashes

This commit is contained in:
Ovahlord committed 2020-04-28 20:42:24 +02:00
1 parent ca76ddf4b5
commit bedd554c79
2 files changed
+13 -6

No files matched your search

@@ -343,15 +343,21 @@ void Minion::RemoveFromWorld()
if (!IsInWorld())
return;
Unit* owner = GetOwner();
if (HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN) || (m_Properties && m_Properties->Title == AsUnderlyingType(SummonTitle::Companion)))
GetOwner()->SetMinion(this, false);
owner->SetMinion(this, false);
else if (!HasUnitTypeMask(UNIT_MASK_PET | UNIT_MASK_HUNTER_PET))
{
GetOwner()->m_Controlled.erase(this);
if (owner->m_Controlled.find(this) != owner->m_Controlled.end())
owner->m_Controlled.erase(this);
else
TC_LOG_FATAL("entities.unit", "Minion::RemoveFromWorld: Owner %s tried to remove a non-existing controlled unit %s from controlled unit set.", owner->GetGUID().ToString().c_str(), GetGUID().ToString().c_str());
if (GetOwner()->IsTotem())
if (Unit* totemOwner = GetOwner()->GetOwner())
totemOwner->m_Controlled.erase(this);
if (owner->IsTotem())
if (Unit* totemOwner = owner->GetOwner())
if (totemOwner->m_Controlled.find(this) != totemOwner->m_Controlled.end())
totemOwner->m_Controlled.erase(this);
}
TempSummon::RemoveFromWorld();
+2 -1
View File
@@ -6195,7 +6195,8 @@ void Unit::SetMinion(Minion* minion, bool apply)
return;
}
m_Controlled.erase(minion);
if (m_Controlled.find(minion) != m_Controlled.end())
m_Controlled.erase(minion);
if (minion->m_Properties && SummonTitle(minion->m_Properties->Title) == SummonTitle::Companion)
if (GetCritterGUID() == minion->GetGUID())