Skip to content

Commit

Permalink
Harden aiObjIsWall() against crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
KJeff01 committed Aug 17, 2023
1 parent 2e9a0cc commit d00a6e2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ai.cpp
Expand Up @@ -819,12 +819,17 @@ void aiObjectAddExpectedDamage(BASE_OBJECT *psObject, SDWORD damage, bool isDire
// see if an object is a wall
static bool aiObjIsWall(BASE_OBJECT *psObj)
{
if (psObj == nullptr)
{
return false;
}
if (psObj->type != OBJ_STRUCTURE)
{
return false;
}

if (((STRUCTURE *)psObj)->pStructureType->type != REF_WALL &&
if (((STRUCTURE *)psObj)->pStructureType &&
((STRUCTURE *)psObj)->pStructureType->type != REF_WALL &&
((STRUCTURE *)psObj)->pStructureType->type != REF_WALLCORNER)
{
return false;
Expand Down Expand Up @@ -1025,6 +1030,10 @@ bool aiChooseSensorTarget(BASE_OBJECT *psObj, BASE_OBJECT **ppsTarget)
for (GridIterator gi = gridList.begin(); gi != gridList.end(); ++gi)
{
BASE_OBJECT *psCurr = *gi;
if (psCurr == nullptr)
{
continue;
}
// Don't target features or doomed/dead objects
if (psCurr->type != OBJ_FEATURE && !psCurr->died && !aiObjectIsProbablyDoomed(psCurr, false))
{
Expand Down

0 comments on commit d00a6e2

Please sign in to comment.