diff options
author | Shauren <shauren.trinity@gmail.com> | 2023-01-19 14:12:08 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2023-01-19 14:14:15 +0100 |
commit | a1b2b86427ce6be2205db0643ad00f546fc076e4 (patch) | |
tree | 0d68e3e719f789065a31a5ab0808c7ffcb9f6963 /src | |
parent | e1a57b3c627a306a1cee56db54625a94ff556149 (diff) |
Core/Auras: Fixed possible iterator invalidation crashes caused by calling UpdateTargetMap inside loops iterating m_appliedAuras
Closes #28609
(cherry picked from commit 593721ff1fc7bb20fa2667625f5d3848a0786c73)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Spells/SpellInfo.cpp | 8 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index bad61444e83..e589e7c3365 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -4019,7 +4019,8 @@ void Unit::RemoveMovementImpairingAuras(bool withRoot) void Unit::RemoveAurasWithMechanic(uint64 mechanicMaskToRemove, AuraRemoveMode removeMode, uint32 exceptSpellId, bool withEffectMechanics) { - RemoveAppliedAuras([=](AuraApplication const* aurApp) + std::vector<Aura*> aurasToUpdateTargets; + RemoveAppliedAuras([=, &aurasToUpdateTargets](AuraApplication const* aurApp) { Aura* aura = aurApp->GetBase(); if (exceptSpellId && aura->GetId() == exceptSpellId) @@ -4034,9 +4035,12 @@ void Unit::RemoveAurasWithMechanic(uint64 mechanicMaskToRemove, AuraRemoveMode r return true; // effect mechanic matches required mask for removal - don't remove, only update targets - aura->UpdateTargetMap(aura->GetCaster()); + aurasToUpdateTargets.push_back(aura); return false; }, removeMode); + + for (Aura* aura : aurasToUpdateTargets) + aura->UpdateTargetMap(aura->GetCaster()); } void Unit::RemoveAurasByShapeShift() diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index 4d5e6ca4d2c..02225a00b81 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -3595,15 +3595,19 @@ void SpellInfo::ApplyAllSpellImmunitiesTo(Unit* target, SpellEffectInfo const& s target->RemoveAurasWithMechanic(mechanicImmunity, AURA_REMOVE_BY_DEFAULT, Id); else { - target->RemoveAppliedAuras([mechanicImmunity](AuraApplication const* aurApp) + std::vector<Aura*> aurasToUpdateTargets; + target->RemoveAppliedAuras([mechanicImmunity, &aurasToUpdateTargets](AuraApplication const* aurApp) { Aura* aura = aurApp->GetBase(); if (aura->GetSpellInfo()->GetAllEffectsMechanicMask() & mechanicImmunity) - aura->UpdateTargetMap(aura->GetCaster()); + aurasToUpdateTargets.push_back(aura); // only update targets, don't remove anything return false; }); + + for (Aura* aura : aurasToUpdateTargets) + aura->UpdateTargetMap(aura->GetCaster()); } } } |