restrict spell state assignment during deletion of spells

This commit is contained in:
Emagi 2024-04-07 07:14:44 -04:00
parent d9d2121b62
commit 231c866c2c
3 changed files with 14 additions and 6 deletions

View file

@ -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<lua_State*, LuaSpell*>::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) {

View file

@ -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);

View file

@ -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);
}