From 86f7a08870ddf9043cbe076ae97272559ac564ab Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sat, 1 Jan 2022 17:55:01 -0500 Subject: [PATCH] Core/Spells: Fix infinite loop Port From (https://github.com/TrinityCore/TrinityCore/commit/e6e73b7b13ddc48f98f46d1af13a95b9cf67cccd) --- Source/Game/Entities/Unit/Unit.Movement.cs | 6 +++++- Source/Game/Spells/Spell.cs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Game/Entities/Unit/Unit.Movement.cs b/Source/Game/Entities/Unit/Unit.Movement.cs index d07637096..27b99c078 100644 --- a/Source/Game/Entities/Unit/Unit.Movement.cs +++ b/Source/Game/Entities/Unit/Unit.Movement.cs @@ -847,10 +847,14 @@ namespace Game.Entities { if (_lastLiquid != null && _lastLiquid.SpellID != 0) RemoveAurasDueToSpell(_lastLiquid.SpellID); + Player player = GetCharmerOrOwnerPlayerOrPlayerItself(); + + // Set _lastLiquid before casting liquid spell to avoid infinite loops + _lastLiquid = curLiquid; + if (curLiquid != null && curLiquid.SpellID != 0 && (!player || !player.IsGameMaster())) CastSpell(this, curLiquid.SpellID, true); - _lastLiquid = curLiquid; // mount capability depends on liquid state change UpdateMountCapability(); diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index feb9d3baa..05becff37 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -3174,7 +3174,10 @@ namespace Game.Spells if (spellInfo != null && spellInfo.IconFileDataId == 134230) { Log.outDebug(LogFilter.Spells, "Statue {0} is unsummoned in spell {1} finish", unitCaster.GetGUID().ToString(), m_spellInfo.Id); - unitCaster.SetDeathState(DeathState.JustDied); + // Avoid infinite loops with setDeathState(JUST_DIED) being called over and over + // It might make sense to do this check in Unit::setDeathState() and all overloaded functions + if (unitCaster.GetDeathState() != DeathState.JustDied) + unitCaster.SetDeathState(DeathState.JustDied); return; } }