mirror of
https://github.com/liyunfan1223/azerothcore-wotlk.git
synced 2026-08-08 07:48:02 +00:00
fix(Core/Unit): avoid iterator invalidation in RemoveAllControlled (#25108)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -8080,10 +8080,11 @@ void Unit::RemoveAllControlled(bool onDeath /*= false*/)
|
|||||||
for (auto it = m_Controlled.begin(); it != m_Controlled.end();)
|
for (auto it = m_Controlled.begin(); it != m_Controlled.end();)
|
||||||
{
|
{
|
||||||
Unit* target = *it;
|
Unit* target = *it;
|
||||||
|
++it;
|
||||||
|
|
||||||
if (target->GetCharmerGUID() == GetGUID())
|
if (target->GetCharmerGUID() == GetGUID())
|
||||||
{
|
{
|
||||||
it = m_Controlled.erase(it);
|
m_Controlled.erase(target);
|
||||||
target->RemoveCharmAuras();
|
target->RemoveCharmAuras();
|
||||||
}
|
}
|
||||||
else if (target->GetOwnerGUID() == GetGUID() && target->IsSummon())
|
else if (target->GetOwnerGUID() == GetGUID() && target->IsSummon())
|
||||||
@@ -8092,23 +8093,15 @@ void Unit::RemoveAllControlled(bool onDeath /*= false*/)
|
|||||||
if (onDeath)
|
if (onDeath)
|
||||||
if (TempSummon* ts = target->ToTempSummon())
|
if (TempSummon* ts = target->ToTempSummon())
|
||||||
if (ts->m_Properties && ts->m_Properties->Type == SUMMON_TYPE_LIGHTWELL)
|
if (ts->m_Properties && ts->m_Properties->Type == SUMMON_TYPE_LIGHTWELL)
|
||||||
{
|
|
||||||
++it;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(onDeath && !IsPlayer() && target->IsGuardian()))
|
if (!(onDeath && !IsPlayer() && target->IsGuardian()))
|
||||||
{
|
|
||||||
target->ToTempSummon()->UnSummon();
|
target->ToTempSummon()->UnSummon();
|
||||||
it = m_Controlled.erase(it);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("entities.unit", "Unit {} is trying to release unit {} which is neither charmed nor owned by it", GetEntry(), target->GetEntry());
|
LOG_ERROR("entities.unit", "Unit {} is trying to release unit {} which is neither charmed nor owned by it", GetEntry(), target->GetEntry());
|
||||||
++it;
|
m_Controlled.erase(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user