diff --git a/source/WorldServer/LuaInterface.cpp b/source/WorldServer/LuaInterface.cpp index ec2d8cc..4a2733d 100644 --- a/source/WorldServer/LuaInterface.cpp +++ b/source/WorldServer/LuaInterface.cpp @@ -623,14 +623,8 @@ LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state, bool needsLock) { } void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell, bool removeSpellScript) { - - MSpellScripts.writelock(__FUNCTION__, __LINE__); - if(needsLock) { - MSpells.lock(); - MSpellDelete.lock(); - } - map::iterator itr = current_spells.find(state); - if(removeSpellScript && itr->second) { + if(removeSpellScript) { + MSpellScripts.writelock(__FUNCTION__, __LINE__); map >::iterator spell_script_itr = spell_scripts.find(cur_spell->file_name); if(spell_script_itr != spell_scripts.end()) { LogWrite(SPELL__DEBUG, 9, "Spell", "LuaInterface::RemoveCurrentSpell spell %s. Queue Entries %u.", cur_spell->file_name.c_str(), spell_script_itr->second.size()); @@ -642,14 +636,20 @@ void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, boo } mutex->releasewritelock(__FUNCTION__, __LINE__); } + 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) { MSpellDelete.unlock(); MSpells.unlock(); } - MSpellScripts.releasewritelock(__FUNCTION__, __LINE__); } bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string customFunction) {