Browse Source

Try to avoid deadlock with spell targets

Emagi 9 months ago
parent
commit
3fbe306f51
1 changed files with 8 additions and 3 deletions
  1. 8 3
      EQ2/source/WorldServer/SpellProcess.cpp

+ 8 - 3
EQ2/source/WorldServer/SpellProcess.cpp

@@ -1998,16 +1998,21 @@ void SpellProcess::RemoveSpellTimersFromSpawn(Spawn* spawn, bool remove_all, boo
 			if (spell->spell->GetSpellData()->persist_through_death)
 				continue;
 
+			bool foundMatch = false;
+			
 			spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
 			for (i = 0; i < spell->targets.size(); i++){
 				if (spawn->GetID() == spell->targets.at(i)){
-					if (spawn->IsEntity())
-						((Entity*)spawn)->RemoveSpellEffect(spell);
-					RemoveTargetFromSpell(spell, spawn, remove_all);
+					foundMatch = true;
 					break;
 				}
 			}
 			spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
+			if(foundMatch) {
+				if (spawn->IsEntity())
+					((Entity*)spawn)->RemoveSpellEffect(spell);
+				RemoveTargetFromSpell(spell, spawn, remove_all);
+			}
 		}
 		if(recast_timers.size() > 0 && delete_recast){			
 			RecastTimer* recast_timer = 0;