From d10554da14fb8371072567f673c9f919cbe6b929 Mon Sep 17 00:00:00 2001 From: Treeston Date: Sun, 23 Jun 2019 16:45:32 +0200 Subject: [PATCH] Entities/Unit: Fix an issue where Unit pointers could be left dangling if a channeled Charm was interrupted by a control aura application. Closes #23440. (cherry picked from commit f4b06fd0b7ead843bba8f5215a09abf7976e012c) --- src/server/game/Entities/Creature/TemporarySummon.cpp | 9 --------- src/server/game/Entities/Creature/TemporarySummon.h | 1 - src/server/game/Entities/Player/Player.cpp | 4 ++++ src/server/game/Entities/Unit/Unit.cpp | 6 +++--- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/server/game/Entities/Creature/TemporarySummon.cpp b/src/server/game/Entities/Creature/TemporarySummon.cpp index e945987428..b63a4cb371 100644 --- a/src/server/game/Entities/Creature/TemporarySummon.cpp +++ b/src/server/game/Entities/Creature/TemporarySummon.cpp @@ -458,12 +458,3 @@ void Puppet::Update(uint32 time) } } } - -void Puppet::RemoveFromWorld() -{ - if (!IsInWorld()) - return; - - RemoveCharmedBy(nullptr); - Minion::RemoveFromWorld(); -} diff --git a/src/server/game/Entities/Creature/TemporarySummon.h b/src/server/game/Entities/Creature/TemporarySummon.h index 2f71f4b593..c2d245744d 100644 --- a/src/server/game/Entities/Creature/TemporarySummon.h +++ b/src/server/game/Entities/Creature/TemporarySummon.h @@ -138,7 +138,6 @@ class TC_GAME_API Puppet : public Minion void InitStats(uint32 duration) override; void InitSummon() override; void Update(uint32 time) override; - void RemoveFromWorld() override; }; class TC_GAME_API ForcedUnsummonDelayEvent : public BasicEvent diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index a4043aa674..ac3bbdf022 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -25737,7 +25737,11 @@ void Player::SetClientControl(Unit* target, bool allowMove) { // still affected by some aura that shouldn't allow control, only allow on last such aura to be removed if (allowMove && target->HasUnitState(UNIT_STATE_CANT_CLIENT_CONTROL)) + { + // this should never happen, otherwise m_unitBeingMoved might be left dangling! + ASSERT(GetUnitBeingMoved() == target); return; + } WorldPackets::Movement::ControlUpdate data; data.Guid = target->GetGUID(); diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index ba78784308..66bae48549 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -10590,12 +10590,14 @@ void Unit::SetControlled(bool apply, UnitState state) if (HasUnitState(state)) return; + if (state & UNIT_STATE_CONTROLLED) + CastStop(); + AddUnitState(state); switch (state) { case UNIT_STATE_STUNNED: SetStunned(true); - CastStop(); break; case UNIT_STATE_ROOT: if (!HasUnitState(UNIT_STATE_STUNNED)) @@ -10608,7 +10610,6 @@ void Unit::SetControlled(bool apply, UnitState state) SendMeleeAttackStop(); // SendAutoRepeatCancel ? SetConfused(true); - CastStop(); } break; case UNIT_STATE_FLEEING: @@ -10618,7 +10619,6 @@ void Unit::SetControlled(bool apply, UnitState state) SendMeleeAttackStop(); // SendAutoRepeatCancel ? SetFeared(true); - CastStop(); } break; default: