Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyCommandCenter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Starcraft AI Course
PyCommandCenter
Commits
ba9d79a0
Commit
ba9d79a0
authored
1 year ago
by
David Bergström
Browse files
Options
Downloads
Patches
Plain Diff
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
1 year ago
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/IDABot.cpp
+1
-1
1 addition, 1 deletion
src/IDABot.cpp
src/Unit.cpp
+30
-13
30 additions, 13 deletions
src/Unit.cpp
with
31 additions
and
14 deletions
src/IDABot.cpp
+
1
−
1
View file @
ba9d79a0
...
...
@@ -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
}
This diff is collapsed.
Click to expand it.
src/Unit.cpp
+
30
−
13
View file @
ba9d79a0
...
...
@@ -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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment