Core/Entities: fix crash

- m_currentSpells and spell would be different in case cancelation of a channeled spell would remove the aura, and aura scripted to cast another channeled spell on remove
- In the above situation, we would lose reference of currentSpell and remove reference from wrong one, this was fixed by clearing the pointer before spell cancelation.

Closes #20172

(cherry picked from commit 5e284d4b38)
This commit is contained in:
ariel-
2018-01-01 17:17:49 -03:00
committed by Shauren
parent e0afca513a
commit b426e64c39
2 changed files with 11 additions and 8 deletions

View File

@@ -3093,14 +3093,15 @@ void Unit::InterruptSpell(CurrentSpellTypes spellType, bool withDelayed, bool wi
if (GetTypeId() == TYPEID_PLAYER)
ToPlayer()->SendAutoRepeatCancel(this);
m_currentSpells[spellType] = nullptr;
if (spell->getState() != SPELL_STATE_FINISHED)
spell->cancel();
else
spell->SetReferencedFromCurrent(false);
if (GetTypeId() == TYPEID_UNIT && IsAIEnabled)
ToCreature()->AI()->OnSpellCastInterrupt(spell->GetSpellInfo());
m_currentSpells[spellType] = nullptr;
spell->SetReferencedFromCurrent(false);
}
}

View File

@@ -3372,13 +3372,15 @@ void Spell::_cast(bool skipCheck)
CallScriptAfterCastHandlers();
if (const std::vector<int32> *spell_triggered = sSpellMgr->GetSpellLinked(m_spellInfo->Id))
if (std::vector<int32> const* spell_triggered = sSpellMgr->GetSpellLinked(m_spellInfo->Id))
{
for (std::vector<int32>::const_iterator i = spell_triggered->begin(); i != spell_triggered->end(); ++i)
if (*i < 0)
m_caster->RemoveAurasDueToSpell(-(*i));
for (int32 id : *spell_triggered)
{
if (id < 0)
m_caster->RemoveAurasDueToSpell(-id);
else
m_caster->CastSpell(m_targets.GetUnitTarget() ? m_targets.GetUnitTarget() : m_caster, *i, true);
m_caster->CastSpell(m_targets.GetUnitTarget() ? m_targets.GetUnitTarget() : m_caster, id, true);
}
}
if (modOwner)