Skip to content

Commit eb0b488

Browse files
Maullerroossienb
andcommitted
[ZH] Reduce crashing within AIPathfind due to inadequate pathing resource cleanup and null pathing info within some cells.
Co-authored-by: Bart Roossien <roossienb@users.noreply.github.com>
1 parent ecd6507 commit eb0b488

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6646,6 +6646,7 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
66466646
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, false );
66476647
parentCell->releaseInfo();
66486648
cleanOpenAndClosedLists();
6649+
goalCell->releaseInfo();
66496650
return path;
66506651
}
66516652

@@ -6722,8 +6723,9 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
67226723
#endif
67236724

67246725
m_isTunneling = false;
6725-
goalCell->releaseInfo();
6726+
parentCell->releaseInfo();
67266727
cleanOpenAndClosedLists();
6728+
goalCell->releaseInfo();
67276729
return NULL;
67286730
}
67296731

@@ -7163,6 +7165,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71637165
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
71647166
parentCell->releaseInfo();
71657167
cleanOpenAndClosedLists();
7168+
goalCell->releaseInfo();
71667169
return path;
71677170
}
71687171

@@ -7367,8 +7370,9 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
73677370
TheGameLogic->incrementOverallFailedPathfinds();
73687371
#endif
73697372
m_isTunneling = false;
7370-
goalCell->releaseInfo();
7373+
parentCell->releaseInfo();
73717374
cleanOpenAndClosedLists();
7375+
goalCell->releaseInfo();
73727376
return NULL;
73737377
}
73747378

@@ -7746,11 +7750,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
77467750
#endif
77477751
}
77487752
#endif
7749-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
7750-
goalCell->releaseInfo();
7751-
}
77527753
parentCell->releaseInfo();
77537754
cleanOpenAndClosedLists();
7755+
goalCell->releaseInfo();
77547756
return path;
77557757
}
77567758

@@ -7947,10 +7949,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79477949
}
79487950
#endif
79497951
#endif
7950-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
7951-
goalCell->releaseInfo();
7952-
}
7952+
parentCell->releaseInfo();
79537953
cleanOpenAndClosedLists();
7954+
goalCell->releaseInfo();
79547955
return path;
79557956
}
79567957

@@ -7997,8 +7998,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79977998
TheGameLogic->incrementOverallFailedPathfinds();
79987999
#endif
79998000
m_isTunneling = false;
8000-
goalCell->releaseInfo();
8001+
parentCell->releaseInfo();
80018002
cleanOpenAndClosedLists();
8003+
goalCell->releaseInfo();
80028004
return NULL;
80038005
}
80048006

@@ -8433,6 +8435,7 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
84338435
}
84348436
#endif
84358437
m_isTunneling = false;
8438+
parentCell->releaseInfo();
84368439
cleanOpenAndClosedLists();
84378440
goalCell->releaseInfo();
84388441
return false;
@@ -8566,7 +8569,9 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85668569
if (parentCell==goalCell) {
85678570
Int cost = parentCell->getTotalCost();
85688571
m_isTunneling = false;
8572+
parentCell->releaseInfo();
85698573
cleanOpenAndClosedLists();
8574+
goalCell->releaseInfo();
85708575
return cost;
85718576
}
85728577

@@ -8678,10 +8683,9 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86788683
}
86798684

86808685
m_isTunneling = false;
8681-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
8682-
goalCell->releaseInfo();
8683-
}
8686+
parentCell->releaseInfo();
86848687
cleanOpenAndClosedLists();
8688+
goalCell->releaseInfo();
86858689
return MAX_COST;
86868690
}
86878691

@@ -8884,8 +8888,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88848888
// construct and return path
88858889
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, blocked);
88868890
parentCell->releaseInfo();
8887-
goalCell->releaseInfo();
88888891
cleanOpenAndClosedLists();
8892+
goalCell->releaseInfo();
88898893
return path;
88908894
}
88918895
// put parent cell onto closed list - its evaluation is finished
@@ -8965,8 +8969,9 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89658969
rawTo->y = closesetCell->getYIndex()*PATHFIND_CELL_SIZE_F + PATHFIND_CELL_SIZE_F/2.0f;
89668970
// construct and return path
89678971
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, closesetCell, centerInCell, blocked );
8968-
goalCell->releaseInfo();
8972+
parentCell->releaseInfo();
89698973
cleanOpenAndClosedLists();
8974+
goalCell->releaseInfo();
89708975
return path;
89718976
}
89728977

@@ -8987,8 +8992,9 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89878992
TheGameLogic->incrementOverallFailedPathfinds();
89888993
#endif
89898994
m_isTunneling = false;
8990-
goalCell->releaseInfo();
8995+
parentCell->releaseInfo();
89918996
cleanOpenAndClosedLists();
8997+
goalCell->releaseInfo();
89928998
return NULL;
89938999
}
89949000

@@ -9110,12 +9116,16 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
91109116
}
91119117
prevCell = cell;
91129118
}
9113-
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9114-
if (goalCellNull) {
9115-
// Very short path.
9116-
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9117-
path->prependNode( &pos, cell->getLayer() );
9119+
9120+
if (cell->hasInfo()) {
9121+
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9122+
if (goalCellNull) {
9123+
// Very short path.
9124+
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9125+
path->prependNode( &pos, cell->getLayer() );
9126+
}
91189127
}
9128+
91199129
// put actual start position as first node on the path, so it begins right at the unit's feet
91209130
if (fromPos->x != path->getFirstNode()->getPosition()->x || fromPos->y != path->getFirstNode()->getPosition()->y) {
91219131
path->prependNode( fromPos, cell->getLayer() );
@@ -10396,6 +10406,7 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1039610406
DEBUG_LOG(("Unit '%s', time %f\n", obj->getTemplate()->getName().str(), (::GetTickCount()-startTimeMS)/1000.0f));
1039710407

1039810408
m_isTunneling = false;
10409+
parentCell->releaseInfo();
1039910410
cleanOpenAndClosedLists();
1040010411
return NULL;
1040110412
}
@@ -10512,6 +10523,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1051210523

1051310524
}
1051410525
if (startNode == originalPath->getLastNode()) {
10526+
parentCell->releaseInfo();
1051510527
cleanOpenAndClosedLists();
1051610528
return NULL; // no open nodes.
1051710529
}
@@ -10580,12 +10592,9 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1058010592
}
1058110593
#endif
1058210594
m_isTunneling = false;
10583-
if (!candidateGoal->getOpen() && !candidateGoal->getClosed())
10584-
{
10585-
// Not on one of the lists
10586-
candidateGoal->releaseInfo();
10587-
}
10595+
parentCell->releaseInfo();
1058810596
cleanOpenAndClosedLists();
10597+
candidateGoal->releaseInfo();
1058910598
return NULL;
1059010599
}
1059110600

@@ -10878,10 +10887,9 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1087810887
}
1087910888
}
1088010889
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10881-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
10882-
goalCell->releaseInfo();
10883-
}
10890+
parentCell->releaseInfo();
1088410891
cleanOpenAndClosedLists();
10892+
goalCell->releaseInfo();
1088510893
return path;
1088610894
}
1088710895
}
@@ -10938,10 +10946,9 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1093810946
TheGameLogic->incrementOverallFailedPathfinds();
1093910947
#endif
1094010948
m_isTunneling = false;
10941-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
10942-
goalCell->releaseInfo();
10943-
}
10949+
parentCell->releaseInfo();
1094410950
cleanOpenAndClosedLists();
10951+
goalCell->releaseInfo();
1094510952
return NULL;
1094610953
}
1094710954

@@ -11099,6 +11106,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1109911106
TheGameLogic->incrementOverallFailedPathfinds();
1110011107
#endif
1110111108
m_isTunneling = false;
11109+
parentCell->releaseInfo();
1110211110
cleanOpenAndClosedLists();
1110311111
return NULL;
1110411112
}

0 commit comments

Comments
 (0)