From 231c866c2cd6eff5b665a6b6430c09ca366a44db Mon Sep 17 00:00:00 2001 From: Emagi Date: Sun, 7 Apr 2024 07:14:44 -0400 Subject: [PATCH] restrict spell state assignment during deletion of spells --- EQ2/source/WorldServer/LuaInterface.cpp | 16 ++++++++++++---- EQ2/source/WorldServer/LuaInterface.h | 2 +- EQ2/source/WorldServer/SpellProcess.cpp | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/EQ2/source/WorldServer/LuaInterface.cpp b/EQ2/source/WorldServer/LuaInterface.cpp index bd8ab30d7..48a66d3b1 100755 --- a/EQ2/source/WorldServer/LuaInterface.cpp +++ b/EQ2/source/WorldServer/LuaInterface.cpp @@ -624,12 +624,18 @@ LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state, bool needsLock) { return spell; } -void LuaInterface::RemoveCurrentSpell(lua_State* state) { - MSpells.lock(); +void LuaInterface::RemoveCurrentSpell(lua_State* state, bool needsLock) { + if(needsLock) { + MSpells.lock(); + MSpellDelete.lock(); + } map::iterator itr = current_spells.find(state); if(itr != current_spells.end()) current_spells.erase(itr); - MSpells.unlock(); + if(needsLock) { + MSpellDelete.unlock(); + MSpells.unlock(); + } } bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string customFunction) { @@ -1570,6 +1576,7 @@ void LuaInterface::AddUserDataPtr(LUAUserData* data, void* data_ptr) { } void LuaInterface::DeletePendingSpells(bool all) { + MSpells.lock(); MSpellDelete.lock(); if (spells_pending_delete.size() > 0) { int32 time = Timer::GetCurrentTime2(); @@ -1609,11 +1616,12 @@ void LuaInterface::DeletePendingSpells(bool all) { } SetLuaUserDataStale(spell); - RemoveCurrentSpell(spell->state); + RemoveCurrentSpell(spell->state, false); safe_delete(spell); } } MSpellDelete.unlock(); + MSpells.unlock(); } void LuaInterface::DeletePendingSpell(LuaSpell* spell) { diff --git a/EQ2/source/WorldServer/LuaInterface.h b/EQ2/source/WorldServer/LuaInterface.h index 68c223292..f0e9c9872 100644 --- a/EQ2/source/WorldServer/LuaInterface.h +++ b/EQ2/source/WorldServer/LuaInterface.h @@ -233,7 +233,7 @@ public: std::string AddSpawnPointers(LuaSpell* spell, bool first_cast, bool precast = false, const char* function = 0, SpellScriptTimer* timer = 0, bool passLuaSpell=false, Spawn* altTarget = 0); LuaSpell* GetCurrentSpell(lua_State* state, bool needsLock = true); - void RemoveCurrentSpell(lua_State* state); + void RemoveCurrentSpell(lua_State* state, bool needsLock = true); bool CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string functionCalled); LuaSpell* GetSpell(const char* name); void UseItemScript(const char* name, lua_State* state, bool val); diff --git a/EQ2/source/WorldServer/SpellProcess.cpp b/EQ2/source/WorldServer/SpellProcess.cpp index 12f6df3de..abd6f7caf 100644 --- a/EQ2/source/WorldServer/SpellProcess.cpp +++ b/EQ2/source/WorldServer/SpellProcess.cpp @@ -2947,7 +2947,7 @@ void SpellProcess::DeleteSpell(LuaSpell* spell) } lua_interface->SetLuaUserDataStale(spell); - lua_interface->RemoveCurrentSpell(spell->state); + lua_interface->RemoveCurrentSpell(spell->state, true); DeleteActiveSpell(spell); }