Update PlayerbotAI.cpp

To avoid crashes, it is important to add nullability checks before trying to access the group leader and remove the bot from the group.
This commit is contained in:
EricksOliveira 2024-10-02 22:48:21 -03:00 committed by GitHub
parent 54a844585f
commit 1a796bed4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -357,6 +357,8 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
if (!bot->InBattleground() && !bot->inRandomLfgDungeon() && bot->GetGroup()) if (!bot->InBattleground() && !bot->inRandomLfgDungeon() && bot->GetGroup())
{ {
Player* leader = bot->GetGroup()->GetLeader(); Player* leader = bot->GetGroup()->GetLeader();
if (leader && leader != bot) // Checks if the leader is valid and is not the bot itself
{
PlayerbotAI* leaderAI = GET_PLAYERBOT_AI(leader); PlayerbotAI* leaderAI = GET_PLAYERBOT_AI(leader);
if (leaderAI && !leaderAI->IsRealPlayer()) if (leaderAI && !leaderAI->IsRealPlayer())
{ {
@ -364,6 +366,7 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
ResetStrategies(); ResetStrategies();
} }
} }
}
bool min = minimal; bool min = minimal;
UpdateAIInternal(elapsed, min); UpdateAIInternal(elapsed, min);