From a479520c33d01cf1099ac1a1045a55272c612cba Mon Sep 17 00:00:00 2001 From: Emagi Date: Sat, 8 Feb 2025 18:19:40 -0500 Subject: [PATCH] reverted some of the mutex lock changes for now since it wasn't resolving all reload spells issues --- source/WorldServer/LuaInterface.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/source/WorldServer/LuaInterface.cpp b/source/WorldServer/LuaInterface.cpp index 62437fa..c509398 100644 --- a/source/WorldServer/LuaInterface.cpp +++ b/source/WorldServer/LuaInterface.cpp @@ -617,7 +617,12 @@ LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state, bool needsLock) { } void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell, bool removeSpellScript) { - if(removeSpellScript) { + if(needsLock) { + MSpells.lock(); + MSpellDelete.lock(); + } + map::iterator itr = current_spells.find(state); + if(removeSpellScript && itr->second) { MSpellScripts.writelock(__FUNCTION__, __LINE__); map >::iterator spell_script_itr = spell_scripts.find(cur_spell->file_name); if(spell_script_itr != spell_scripts.end()) { @@ -632,12 +637,6 @@ void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, boo } MSpellScripts.releasewritelock(__FUNCTION__, __LINE__); } - - if(needsLock) { - MSpells.lock(); - MSpellDelete.lock(); - } - map::iterator itr = current_spells.find(state); if(itr != current_spells.end() && removeCurSpell) current_spells.erase(itr); if(needsLock) { @@ -2380,8 +2379,8 @@ LuaSpell* LuaInterface::GetSpellScript(const char* name, bool create_new, bool u LuaSpell* ret = 0; Mutex* mutex = 0; - MSpellScripts.writelock(__FUNCTION__, __LINE__); MSpells.lock(); + MSpellScripts.writelock(__FUNCTION__, __LINE__); itr = spell_scripts.find(name); if(itr != spell_scripts.end()) { mutex = GetSpellScriptMutex(name); @@ -2399,8 +2398,8 @@ LuaSpell* LuaInterface::GetSpellScript(const char* name, bool create_new, bool u } mutex->releasewritelock(__FUNCTION__, __LINE__); } - MSpells.unlock(); MSpellScripts.releasewritelock(__FUNCTION__, __LINE__); + MSpells.unlock(); if(!ret && create_new){ if(!name || (ret = LoadSpellScript(name)) == nullptr) {