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:
hondacrx
2023-01-24 23:08:20 -05:00
parent edcdfa95c4
commit 06c6c8afc7
2 changed files with 10 additions and 2 deletions
+5 -1
View File
@@ -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)
{
+5 -1
View File
@@ -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());
}
}
}