Skip to content

Commit 94b6629

Browse files
Maullerroossienb
andcommitted
[ZH] Add more places to prevent cells leaking pathing info if they fail some conditions
Co-authored-by: Bart Roossien <roossienb@users.noreply.github.com>
1 parent 7c6d0c0 commit 94b6629

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6561,10 +6561,14 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
65616561
zone2 = m_zoneManager.getEffectiveZone(locomotorSet.getValidSurfaces(), isCrusher, goalCell->getZone());
65626562

65636563
if (layer==LAYER_WALL && zone1 == 0) {
6564+
goalCell->releaseInfo();
6565+
parentCell->releaseInfo();
65646566
return NULL;
65656567
}
65666568

65676569
if (destinationLayer==LAYER_WALL && zone2 == 0) {
6570+
goalCell->releaseInfo();
6571+
parentCell->releaseInfo();
65686572
return NULL;
65696573
}
65706574

@@ -6646,7 +6650,6 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
66466650
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, false );
66476651
parentCell->releaseInfo();
66486652
cleanOpenAndClosedLists();
6649-
goalCell->releaseInfo();
66506653
return path;
66516654
}
66526655

@@ -7101,6 +7104,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71017104
PathfindLayerEnum layer = TheTerrainLogic->getLayerForDestination(from);
71027105
PathfindCell *parentCell = getClippedCell( layer,&clipFrom );
71037106
if (parentCell == NULL) {
7107+
goalCell->releaseInfo();
71047108
return NULL;
71057109
}
71067110
if (parentCell!=goalCell) {
@@ -7160,7 +7164,6 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71607164
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
71617165
parentCell->releaseInfo();
71627166
cleanOpenAndClosedLists();
7163-
goalCell->releaseInfo();
71647167
return path;
71657168
}
71667169

@@ -8249,7 +8252,6 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
82498252

82508253
if (parentCell!=goalCell) {
82518254
if (!parentCell->allocateInfo(startCellNdx)) {
8252-
desiredCell->releaseInfo();
82538255
goalCell->releaseInfo();
82548256
return FALSE;
82558257
}
@@ -8364,6 +8366,8 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
83648366

83658367
if (!newCell->allocateInfo(newCellCoord)) {
83668368
// Out of cells for pathing...
8369+
cleanOpenAndClosedLists();
8370+
goalCell->releaseInfo();
83678371
return cellCount;
83688372
}
83698373
cellCount++;
@@ -8548,18 +8552,17 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85488552
parentCell = m_openList;
85498553
m_openList = parentCell->removeFromOpenList(m_openList);
85508554

8551-
// put parent cell onto closed list - its evaluation is finished
8552-
m_closedList = parentCell->putOnClosedList( m_closedList );
8553-
85548555
if (parentCell==goalCell) {
85558556
Int cost = parentCell->getTotalCost();
85568557
m_isTunneling = false;
85578558
parentCell->releaseInfo();
85588559
cleanOpenAndClosedLists();
8559-
goalCell->releaseInfo();
85608560
return cost;
85618561
}
85628562

8563+
// put parent cell onto closed list - its evaluation is finished
8564+
m_closedList = parentCell->putOnClosedList( m_closedList );
8565+
85638566
if (cellCount > MAX_CELL_COUNT) {
85648567
continue;
85658568
}
@@ -8620,8 +8623,11 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86208623

86218624
if (!newCell->allocateInfo(newCellCoord)) {
86228625
// Out of cells for pathing...
8626+
parentCell->releaseInfo();
8627+
cleanOpenAndClosedLists();
8628+
goalCell->releaseInfo();
86238629
return cellCount;
8624-
}
8630+
}
86258631
cellCount++;
86268632

86278633
newCostSoFar = newCell->costSoFar( parentCell );
@@ -8807,6 +8813,7 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88078813
if (parentCell!=goalCell) {
88088814
worldToCell(&clipFrom, &pos2d);
88098815
if (!parentCell->allocateInfo(pos2d)) {
8816+
goalCell->releaseInfo();
88108817
return NULL;
88118818
}
88128819
}
@@ -9102,13 +9109,11 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
91029109
prevCell = cell;
91039110
}
91049111

9105-
if (cell->hasInfo()) {
9106-
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9107-
if (goalCellNull) {
9108-
// Very short path.
9109-
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9110-
path->prependNode( &pos, cell->getLayer() );
9111-
}
9112+
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9113+
if (goalCellNull) {
9114+
// Very short path.
9115+
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9116+
path->prependNode( &pos, cell->getLayer() );
91129117
}
91139118

91149119
// put actual start position as first node on the path, so it begins right at the unit's feet
@@ -10509,14 +10514,14 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1050910514
}
1051010515
if (startNode == originalPath->getLastNode()) {
1051110516
parentCell->releaseInfo();
10512-
cleanOpenAndClosedLists();
1051310517
return NULL; // no open nodes.
1051410518
}
1051510519
PathfindCell *candidateGoal;
1051610520
candidateGoal = getCell(LAYER_GROUND, &goalPos); // just using for cost estimates.
1051710521
ICoord2D goalCellNdx;
1051810522
worldToCell(&goalPos, &goalCellNdx);
1051910523
if (!candidateGoal->allocateInfo(goalCellNdx)) {
10524+
parentCell->releaseInfo();
1052010525
return NULL;
1052110526
}
1052210527

0 commit comments

Comments
 (0)