Skip to content

Commit 262b2d9

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 eb0b488 commit 262b2d9

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) {
@@ -7165,7 +7169,6 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71657169
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
71667170
parentCell->releaseInfo();
71677171
cleanOpenAndClosedLists();
7168-
goalCell->releaseInfo();
71697172
return path;
71707173
}
71717174

@@ -8264,7 +8267,6 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
82648267

82658268
if (parentCell!=goalCell) {
82668269
if (!parentCell->allocateInfo(startCellNdx)) {
8267-
desiredCell->releaseInfo();
82688270
goalCell->releaseInfo();
82698271
return FALSE;
82708272
}
@@ -8379,6 +8381,8 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
83798381

83808382
if (!newCell->allocateInfo(newCellCoord)) {
83818383
// Out of cells for pathing...
8384+
cleanOpenAndClosedLists();
8385+
goalCell->releaseInfo();
83828386
return cellCount;
83838387
}
83848388
cellCount++;
@@ -8563,18 +8567,17 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85638567
parentCell = m_openList;
85648568
m_openList = parentCell->removeFromOpenList(m_openList);
85658569

8566-
// put parent cell onto closed list - its evaluation is finished
8567-
m_closedList = parentCell->putOnClosedList( m_closedList );
8568-
85698570
if (parentCell==goalCell) {
85708571
Int cost = parentCell->getTotalCost();
85718572
m_isTunneling = false;
85728573
parentCell->releaseInfo();
85738574
cleanOpenAndClosedLists();
8574-
goalCell->releaseInfo();
85758575
return cost;
85768576
}
85778577

8578+
// put parent cell onto closed list - its evaluation is finished
8579+
m_closedList = parentCell->putOnClosedList( m_closedList );
8580+
85788581
if (cellCount > MAX_CELL_COUNT) {
85798582
continue;
85808583
}
@@ -8635,8 +8638,11 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86358638

86368639
if (!newCell->allocateInfo(newCellCoord)) {
86378640
// Out of cells for pathing...
8641+
parentCell->releaseInfo();
8642+
cleanOpenAndClosedLists();
8643+
goalCell->releaseInfo();
86388644
return cellCount;
8639-
}
8645+
}
86408646
cellCount++;
86418647

86428648
newCostSoFar = newCell->costSoFar( parentCell );
@@ -8822,6 +8828,7 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88228828
if (parentCell!=goalCell) {
88238829
worldToCell(&clipFrom, &pos2d);
88248830
if (!parentCell->allocateInfo(pos2d)) {
8831+
goalCell->releaseInfo();
88258832
return NULL;
88268833
}
88278834
}
@@ -9117,13 +9124,11 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
91179124
prevCell = cell;
91189125
}
91199126

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-
}
9127+
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9128+
if (goalCellNull) {
9129+
// Very short path.
9130+
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9131+
path->prependNode( &pos, cell->getLayer() );
91279132
}
91289133

91299134
// put actual start position as first node on the path, so it begins right at the unit's feet
@@ -10524,14 +10529,14 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1052410529
}
1052510530
if (startNode == originalPath->getLastNode()) {
1052610531
parentCell->releaseInfo();
10527-
cleanOpenAndClosedLists();
1052810532
return NULL; // no open nodes.
1052910533
}
1053010534
PathfindCell *candidateGoal;
1053110535
candidateGoal = getCell(LAYER_GROUND, &goalPos); // just using for cost estimates.
1053210536
ICoord2D goalCellNdx;
1053310537
worldToCell(&goalPos, &goalCellNdx);
1053410538
if (!candidateGoal->allocateInfo(goalCellNdx)) {
10539+
parentCell->releaseInfo();
1053510540
return NULL;
1053610541
}
1053710542

0 commit comments

Comments
 (0)