Skip to content
Snippets Groups Projects
Commit ba9d79a0 authored by David Bergström's avatar David Bergström
Browse files

Fix segfault errors in getTarget and hasTarget on Linux

parent 1b8e573c
No related branches found
No related tags found
No related merge requests found
Pipeline #115039 passed
......@@ -383,4 +383,4 @@ float IDABot::UpgradeResearchTime(sc2::UpgradeID upgrade_id) const
float IDABot::RadiusEffect(sc2::EffectID effect_id) const
{
return Observation()->GetEffectData()[effect_id].radius;
}
\ No newline at end of file
}
......@@ -337,16 +337,27 @@ Unit Unit::getTarget() const
BOT_ASSERT(isValid(), "Unit is not valid");
// if unit has order, check tag of target of first order
if(getUnitPtr()->orders.size() > 0){
// t_id is set to the unit tag of the target
CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
// if it doesn't have a target. Return itself
if (m_bot->GetUnit(t_id) == nullptr) {
return *this;
}
// t_id is set to the unit tag of the target
CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
// Make sure the returned tag is not the NullTag
if (t_id == sc2::NullTag) {
return *this;
}
// Make sure the Tag references a valid unit
if (m_bot->Observation()->GetUnit(t_id) == nullptr) {
return *this;
}
// IDABot finds the unit with this tag
return m_bot->GetUnit(t_id);
// Convert the tag to a Unit object
Unit unit = m_bot->GetUnit(t_id);
if (unit.isValid()) {
return unit;
} else {
return *this;
}
}
return *this;
}
......@@ -356,10 +367,16 @@ bool Unit::hasTarget() const
BOT_ASSERT(isValid(), "Unit is not valid");
if (getUnitPtr()->orders.size() > 0) {
if (getUnitPtr()->orders[0].target_unit_tag != NULL) {
if (getUnitPtr()->orders[0].target_unit_tag != sc2::NullTag) {
CCUnitID t_id = getUnitPtr()->orders[0].target_unit_tag;
// IDABot finds the unit with this tag, and returns true if valid
return m_bot->GetUnit(t_id).isValid();
if (m_bot->Observation()->GetUnit(t_id) == nullptr) {
return false;
}
Unit unit = m_bot->GetUnit(t_id);
return unit.isValid();
}
}
......@@ -504,4 +521,4 @@ float Unit::maxShields() const
float Unit::maxEnergy() const
{
return m_unit->energy_max;
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment