fix(Core/Pets): Fix crash when pet tries to attack deleted object (#17034)

This situation occurs when, during a fight, a pet receives a command to apply a positive spell to an ally and then resume attacking its previous target.
This commit is contained in:
Anton Popovichenko
2023-08-19 22:27:51 +02:00
committed by GitHub
parent 7529994a5c
commit f6b77f9d64
3 changed files with 22 additions and 14 deletions

View File

@@ -530,7 +530,7 @@ void WorldSession::HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint32 spe
pet->SendPetAIReaction(guid1);
}
pet->ToPet()->CastWhenWillAvailable(spellId, unit_target, nullptr, tempspellIsPositive);
pet->ToPet()->CastWhenWillAvailable(spellId, unit_target, ObjectGuid::Empty, tempspellIsPositive);
}
}
else if (haspositiveeffect)
@@ -566,7 +566,11 @@ void WorldSession::HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint32 spe
pet->SendPetAIReaction(guid1);
}
pet->ToPet()->CastWhenWillAvailable(spellId, unit_target, victim, tmpSpellIsPositive);
ObjectGuid oldTarget = ObjectGuid::Empty;
if (victim)
oldTarget = victim->GetGUID();
pet->ToPet()->CastWhenWillAvailable(spellId, unit_target, oldTarget, tmpSpellIsPositive);
}
}
}