Skip to content

Commit

Permalink
Store cast item GUID in Spell to prevent crash when item is deleted
Browse files Browse the repository at this point in the history
Signed-off-by: sidsukana <pgsilent@gmail.com>
  • Loading branch information
mityada authored and Phatcat committed Jun 24, 2016
1 parent 306bea4 commit e8638d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/game/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,9 @@ void Spell::SpellStart(SpellCastTargets const* targets, Aura* triggeredByAura)
m_spellState = SPELL_STATE_STARTING;
m_targets = *targets;

if (m_CastItem)
m_CastItemGuid = m_CastItem->GetObjectGuid();

m_castPositionX = m_caster->GetPositionX();
m_castPositionY = m_caster->GetPositionY();
m_castPositionZ = m_caster->GetPositionZ();
Expand Down Expand Up @@ -3593,6 +3596,12 @@ void Spell::update(uint32 difftime)
return;
}

if (m_CastItemGuid && !m_CastItem)
{
cancel();
return;
}

// check if the player or unit caster has moved before the spell finished (exclude casting on vehicles)
if (((m_caster->GetTypeId() == TYPEID_PLAYER || m_caster->GetTypeId() == TYPEID_UNIT) && m_timer != 0) &&
(m_castPositionX != m_caster->GetPositionX() || m_castPositionY != m_caster->GetPositionY() || m_castPositionZ != m_caster->GetPositionZ()) &&
Expand Down Expand Up @@ -4642,6 +4651,7 @@ void Spell::TakeReagents()
}

m_CastItem = nullptr;
m_CastItemGuid.Clear();
}
}

Expand Down Expand Up @@ -7115,6 +7125,11 @@ void Spell::UpdatePointers()
UpdateOriginalCasterPointer();

m_targets.Update(m_caster);

if (m_caster->GetTypeId() == TYPEID_PLAYER)
m_CastItem = ((Player *)m_caster)->GetItemByGuid(m_CastItemGuid);
else
m_CastItem = nullptr;
}

bool Spell::CheckTargetCreatureType(Unit* target) const
Expand Down Expand Up @@ -7666,6 +7681,7 @@ void Spell::ClearCastItem()
m_targets.setItemTarget(nullptr);

m_CastItem = nullptr;
m_CastItemGuid.Clear();
}

bool Spell::HasGlobalCooldown()
Expand Down
2 changes: 2 additions & 0 deletions src/game/Spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ class Spell
SpellEntry const* m_spellInfo;
SpellEntry const* m_triggeredBySpellInfo;
int32 m_currentBasePoints[MAX_EFFECT_INDEX]; // cache SpellEntry::CalculateSimpleValue and use for set custom base points

ObjectGuid m_CastItemGuid;
Item* m_CastItem;
uint8 m_cast_count;
uint32 m_glyphIndex;
Expand Down

0 comments on commit e8638d5

Please sign in to comment.