1
0

Fix the handling in RemoveCurrentSpell

This commit is contained in:
Emagi 2025-02-07 14:53:23 -05:00
parent b693deb4f8
commit a062c5f8d7

View File

@ -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) { void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell, bool removeSpellScript) {
if(removeSpellScript) {
MSpellScripts.writelock(__FUNCTION__, __LINE__); MSpellScripts.writelock(__FUNCTION__, __LINE__);
if(needsLock) {
MSpells.lock();
MSpellDelete.lock();
}
map<lua_State*, LuaSpell*>::iterator itr = current_spells.find(state);
if(removeSpellScript && itr->second) {
map<string, map<lua_State*, LuaSpell*> >::iterator spell_script_itr = spell_scripts.find(cur_spell->file_name); map<string, map<lua_State*, LuaSpell*> >::iterator spell_script_itr = spell_scripts.find(cur_spell->file_name);
if(spell_script_itr != spell_scripts.end()) { 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()); 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__); mutex->releasewritelock(__FUNCTION__, __LINE__);
} }
MSpellScripts.releasewritelock(__FUNCTION__, __LINE__);
} }
if(needsLock) {
MSpells.lock();
MSpellDelete.lock();
}
map<lua_State*, LuaSpell*>::iterator itr = current_spells.find(state);
if(itr != current_spells.end() && removeCurSpell) if(itr != current_spells.end() && removeCurSpell)
current_spells.erase(itr); current_spells.erase(itr);
if(needsLock) { if(needsLock) {
MSpellDelete.unlock(); MSpellDelete.unlock();
MSpells.unlock(); MSpells.unlock();
} }
MSpellScripts.releasewritelock(__FUNCTION__, __LINE__);
} }
bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string customFunction) { bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string customFunction) {