From a6a0ca85ef171c08a93c47a6c6e765e327227f64 Mon Sep 17 00:00:00 2001 From: Emagi Date: Tue, 17 Jun 2025 08:14:10 -0400 Subject: [PATCH] Crash fix on spell deletion, remove from pending spells if we already plan to delete --- source/WorldServer/LuaInterface.cpp | 8 +------- source/WorldServer/SpellProcess.cpp | 5 ++++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/source/WorldServer/LuaInterface.cpp b/source/WorldServer/LuaInterface.cpp index edb2e4e..e23fc2b 100644 --- a/source/WorldServer/LuaInterface.cpp +++ b/source/WorldServer/LuaInterface.cpp @@ -1737,7 +1737,6 @@ void LuaInterface::DeletePendingSpells(bool all) { if(!all) { // rely on targets the spell->caster could be corrupt - bool spellDeleted = false; if(spell->targets.size() > 0) { spell->MSpellTargets.readlock(__FUNCTION__, __LINE__); for (int8 i = 0; i < spell->targets.size(); i++) { @@ -1748,16 +1747,11 @@ void LuaInterface::DeletePendingSpells(bool all) { if(target->IsEntity()) { ((Entity*)target)->RemoveWard(spell); } - - if(!spellDeleted && spell->zone && spell->zone->GetSpellProcess()) - spell->zone->GetSpellProcess()->DeleteActiveSpell(spell, true); - - spellDeleted = true; } spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__); } - if(!spellDeleted && spell->zone && spell->zone->GetSpellProcess()) { + if(spell->zone && spell->zone->GetSpellProcess()) { spell->zone->GetSpellProcess()->DeleteActiveSpell(spell, true); } } diff --git a/source/WorldServer/SpellProcess.cpp b/source/WorldServer/SpellProcess.cpp index 2fda560..b195569 100644 --- a/source/WorldServer/SpellProcess.cpp +++ b/source/WorldServer/SpellProcess.cpp @@ -3067,9 +3067,12 @@ void SpellProcess::AddSelfAndPetToCharTargets(LuaSpell* spell, Spawn* caster, bo spell->char_id_targets.insert(make_pair(charID, 0x00)); } -void SpellProcess::DeleteActiveSpell(LuaSpell* spell, bool skipRemoveCurrent) { +void SpellProcess::DeleteActiveSpell(LuaSpell* spell, bool skipRemoveCurrent) { + lua_interface->SetLuaUserDataStale(spell); if(!skipRemoveCurrent) lua_interface->RemoveCurrentSpell(spell->state, spell, true); + + lua_interface->DeletePendingSpell(spell); active_spells.Remove(spell, true, 10000); }