1
0

Update LuaInterface::DestroySpells to assure we cover all the new lua states under the spell_scripts instead of the obselete spells map

This commit is contained in:
Emagi 2024-09-06 08:10:47 -04:00
parent 14003ee3a4
commit fb592b4d76
2 changed files with 19 additions and 12 deletions

View File

@ -143,17 +143,25 @@ void LuaInterface::Process() {
}
void LuaInterface::DestroySpells() {
map<string, LuaSpell*>::iterator itr;
MSpells.lock();
for(itr = spells.begin(); itr != spells.end(); itr++){
map<string, map<lua_State*, LuaSpell*> >::iterator spell_script_itr;
for(spell_script_itr = spell_scripts.begin(); spell_script_itr != spell_scripts.end(); spell_script_itr++) {
map<lua_State*, LuaSpell*>::iterator inner_itr;
for(inner_itr = spell_script_itr->second.begin(); inner_itr != spell_script_itr->second.end(); inner_itr++) {
LuaSpell* cur_spell = inner_itr->second;
MSpellDelete.lock();
RemoveCurrentSpell(itr->second->state, itr->second, false);
RemoveCurrentSpell(inner_itr->first, inner_itr->second, false, true, false);
MSpellDelete.unlock();
lua_close(itr->second->state);
safe_delete(itr->second);
lua_close(inner_itr->first);
safe_delete(cur_spell);
}
Mutex* mutex = GetSpellScriptMutex(spell_script_itr->first.c_str());
safe_delete(mutex);
}
current_spells.clear();
spell_scripts_mutex.clear();
spell_scripts.clear();
spells.clear();
MSpells.unlock();
}
@ -597,13 +605,13 @@ LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state, bool needsLock) {
return spell;
}
void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell) {
void LuaInterface::RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock, bool removeCurSpell, bool removeSpellScript) {
if(needsLock) {
MSpells.lock();
MSpellDelete.lock();
}
map<lua_State*, LuaSpell*>::iterator itr = current_spells.find(state);
if(itr->second) {
if(removeSpellScript && itr->second) {
MSpellScripts.readlock(__FUNCTION__, __LINE__);
map<string, map<lua_State*, LuaSpell*> >::iterator spell_script_itr = spell_scripts.find(cur_spell->file_name);
if(spell_script_itr != spell_scripts.end()) {

View File

@ -234,7 +234,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, LuaSpell* cur_spell, bool needsLock = true, bool removeCurSpell = true);
void RemoveCurrentSpell(lua_State* state, LuaSpell* cur_spell, bool needsLock = true, bool removeCurSpell = true, bool removeSpellScript = 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);
@ -322,7 +322,6 @@ private:
vector<string>* GetDirectoryListing(const char* directory);
lua_State* LoadLuaFile(const char* name);
void RegisterFunctions(lua_State* state);
map<string, LuaSpell*> spells;
map<lua_State*, string> inverse_spells;
map<int32, Quest*> quests;