Skip to content

Commit

Permalink
Playerbot: Fix crash due to floating point exception
Browse files Browse the repository at this point in the history
In some cases, Unit::GetMaxHealth() can be 0 resulting in a floating
point exception.
Add a check to prevent that and force the health percentage to 0 as
such a player is obviously dead.
  • Loading branch information
cala committed Oct 3, 2017
1 parent c942eee commit cc0abae
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/game/PlayerBot/Base/PlayerbotClassAI.cpp
Expand Up @@ -242,6 +242,7 @@ Player* PlayerbotClassAI::GetHealTarget(JOB_TYPE type)

// define seperately for sorting purposes - DO NOT CHANGE ORDER!
std::vector<heal_priority> targets;
uint8 uiHealthPercentage;

// First, fill the list of targets
if (m_bot->GetGroup())
Expand All @@ -254,14 +255,20 @@ Player* PlayerbotClassAI::GetHealTarget(JOB_TYPE type)
continue;
JOB_TYPE job = GetTargetJob(groupMember);
if (job & type)
targets.push_back( heal_priority(groupMember, (groupMember->GetHealth() * 100 / groupMember->GetMaxHealth()), job) );
{
uiHealthPercentage = int(groupMember->GetMaxHealth() != 0 ? groupMember->GetHealth() * 100 / groupMember->GetMaxHealth() : 0);
targets.push_back( heal_priority(groupMember, uiHealthPercentage, job) );
}
}
}
else
{
targets.push_back( heal_priority(m_bot, m_bot->GetHealthPercent(), GetTargetJob(m_bot)) );
if (m_master && !m_master->IsInDuel())
targets.push_back( heal_priority(m_master, (m_master->GetHealth() * 100 / m_master->GetMaxHealth()), GetTargetJob(m_master)) );
{
uiHealthPercentage = int(m_master->GetMaxHealth() != 0 ? m_master->GetHealth() * 100 / m_master->GetMaxHealth() : 0);
targets.push_back( heal_priority(m_master, uiHealthPercentage, GetTargetJob(m_master)) );
}
}

// Sorts according to type: Healers first, tanks next, then master followed by DPS, thanks to the order of the TYPE enum
Expand Down

0 comments on commit cc0abae

Please sign in to comment.