Core/Auras: Fixed possible iterator invalidation crashes caused by calling UpdateTargetMap inside loops iterating m_appliedAuras
Port From (https://github.com/TrinityCore/TrinityCore/commit/a1b2b86427ce6be2205db0643ad00f546fc076e4)
This commit is contained in:
@@ -2928,6 +2928,7 @@ namespace Game.Entities
|
||||
|
||||
public void RemoveAurasWithMechanic(ulong mechanicMaskToRemove, AuraRemoveMode removeMode = AuraRemoveMode.Default, uint exceptSpellId = 0, bool withEffectMechanics = false)
|
||||
{
|
||||
List<Aura> aurasToUpdateTargets = new();
|
||||
RemoveAppliedAuras(aurApp =>
|
||||
{
|
||||
Aura aura = aurApp.GetBase();
|
||||
@@ -2943,9 +2944,12 @@ namespace Game.Entities
|
||||
return true;
|
||||
|
||||
// effect mechanic matches required mask for removal - don't remove, only update targets
|
||||
aura.UpdateTargetMap(aura.GetCaster());
|
||||
aurasToUpdateTargets.Add(aura);
|
||||
return false;
|
||||
}, removeMode);
|
||||
|
||||
foreach (Aura aura in aurasToUpdateTargets)
|
||||
aura.UpdateTargetMap(aura.GetCaster());
|
||||
}
|
||||
public void RemoveAurasDueToSpellBySteal(uint spellId, ObjectGuid casterGUID, WorldObject stealer, int stolenCharges = 1)
|
||||
{
|
||||
|
||||
@@ -2439,15 +2439,19 @@ namespace Game.Spells
|
||||
target.RemoveAurasWithMechanic(mechanicImmunity, AuraRemoveMode.Default, Id);
|
||||
else
|
||||
{
|
||||
List<Aura> aurasToUpdateTargets = new();
|
||||
target.RemoveAppliedAuras(aurApp =>
|
||||
{
|
||||
Aura aura = aurApp.GetBase();
|
||||
if ((aura.GetSpellInfo().GetAllEffectsMechanicMask() & mechanicImmunity) != 0)
|
||||
aura.UpdateTargetMap(aura.GetCaster());
|
||||
aurasToUpdateTargets.Add(aura);
|
||||
|
||||
// only update targets, don't remove anything
|
||||
return false;
|
||||
});
|
||||
|
||||
foreach (Aura aura in aurasToUpdateTargets)
|
||||
aura.UpdateTargetMap(aura.GetCaster());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user