Procházet zdrojové kódy

restrict spell state assignment during deletion of spells

Emagi před 7 měsíci
rodič
revize
231c866c2c

+ 12 - 4
EQ2/source/WorldServer/LuaInterface.cpp

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

+ 1 - 1
EQ2/source/WorldServer/LuaInterface.h

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

+ 1 - 1
EQ2/source/WorldServer/SpellProcess.cpp

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