Core/Movement: Fix a potential crash on newly created pets. Closes #21791.

(cherry picked from commit 74defba5a7)
This commit is contained in:
Treeston
2018-04-07 17:23:26 +02:00
committed by Shauren
parent d76db70cbf
commit 3d9d6fbcb8
3 changed files with 3 additions and 2 deletions

View File

@@ -8064,7 +8064,7 @@ void Unit::UpdateSpeed(UnitMoveType mtype)
if (creature->HasUnitTypeMask(UNIT_MASK_MINION) && !creature->IsInCombat())
{
MovementGenerator* top = creature->GetMotionMaster()->top();
MovementGenerator* top = creature->GetMotionMaster()->topOrNull();
if (top && top->GetMovementGeneratorType() == FOLLOW_MOTION_TYPE)
{
Unit* followed = ASSERT_NOTNULL(dynamic_cast<AbstractFollower*>(top))->GetTarget();

View File

@@ -144,6 +144,7 @@ class TC_GAME_API MotionMaster
bool empty() const { return (_top < 0); }
int size() const { return _top + 1; }
MovementGenerator* topOrNull() const { return empty() ? nullptr : top(); }
MovementGenerator* top() const { ASSERT(!empty()); return _slot[_top]; }
void Initialize();

View File

@@ -26,7 +26,7 @@
static bool IsMutualChase(Unit* owner, Unit* target)
{
MovementGenerator const* gen = target->GetMotionMaster()->top();
MovementGenerator const* gen = target->GetMotionMaster()->topOrNull();
if (!gen || gen->GetMovementGeneratorType() != CHASE_MOTION_TYPE)
return false;
return (static_cast<ChaseMovementGenerator const*>(gen)->GetTarget() == owner);