From 4b1e65d057a5a18c6c36defc6ca993ba62d2036f Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 14 Dec 2012 11:06:56 -0500 Subject: [PATCH] Core/PetAI: Fixed a crash in PetAI::CanAttack Closes #8660 --- src/server/game/AI/CoreAI/PetAI.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index a860c8152c..b7fa3940a2 100644 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -550,10 +550,14 @@ bool PetAI::CanAttack(Unit* target) return (me->IsWithinMeleeRange(target) || me->GetCharmInfo()->IsCommandAttack()); // Pets attacking something (or chasing) should only switch targets if owner tells them to - if (me->getVictim() && (me->getVictim() != target)) + if (me->getVictim() && me->getVictim() != target) { // Check if our owner selected this target and clicked "attack" - Unit* ownerTarget = me->GetCharmerOrOwner()->ToPlayer()->GetSelectedUnit(); + Unit* ownerTarget = NULL; + if (Player* owner = me->GetCharmerOrOwner()->ToPlayer()) + ownerTarget = owner->GetSelectedUnit(); + else + ownerTarget = me->GetCharmerOrOwner()->getVictim(); if (ownerTarget && me->GetCharmInfo()->IsCommandAttack()) return (target->GetGUID() == ownerTarget->GetGUID());