Skip to content

Commit de665de

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 add0ba6 commit de665de

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
@@ -6565,10 +6565,14 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
65656565
zone2 = m_zoneManager.getEffectiveZone(locomotorSet.getValidSurfaces(), isCrusher, goalCell->getZone());
65666566

65676567
if (layer==LAYER_WALL && zone1 == 0) {
6568+
goalCell->releaseInfo();
6569+
parentCell->releaseInfo();
65686570
return NULL;
65696571
}
65706572

65716573
if (destinationLayer==LAYER_WALL && zone2 == 0) {
6574+
goalCell->releaseInfo();
6575+
parentCell->releaseInfo();
65726576
return NULL;
65736577
}
65746578

@@ -6650,7 +6654,6 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
66506654
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, false );
66516655
parentCell->releaseInfo();
66526656
cleanOpenAndClosedLists();
6653-
goalCell->releaseInfo();
66546657
return path;
66556658
}
66566659

@@ -7105,6 +7108,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71057108
PathfindLayerEnum layer = TheTerrainLogic->getLayerForDestination(from);
71067109
PathfindCell *parentCell = getClippedCell( layer,&clipFrom );
71077110
if (parentCell == NULL) {
7111+
goalCell->releaseInfo();
71087112
return NULL;
71097113
}
71107114
if (parentCell!=goalCell) {
@@ -7169,7 +7173,6 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71697173
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
71707174
parentCell->releaseInfo();
71717175
cleanOpenAndClosedLists();
7172-
goalCell->releaseInfo();
71737176
return path;
71747177
}
71757178

@@ -8268,7 +8271,6 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
82688271

82698272
if (parentCell!=goalCell) {
82708273
if (!parentCell->allocateInfo(startCellNdx)) {
8271-
desiredCell->releaseInfo();
82728274
goalCell->releaseInfo();
82738275
return FALSE;
82748276
}
@@ -8383,6 +8385,8 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
83838385

83848386
if (!newCell->allocateInfo(newCellCoord)) {
83858387
// Out of cells for pathing...
8388+
cleanOpenAndClosedLists();
8389+
goalCell->releaseInfo();
83868390
return cellCount;
83878391
}
83888392
cellCount++;
@@ -8567,18 +8571,17 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85678571
parentCell = m_openList;
85688572
m_openList = parentCell->removeFromOpenList(m_openList);
85698573

8570-
// put parent cell onto closed list - its evaluation is finished
8571-
m_closedList = parentCell->putOnClosedList( m_closedList );
8572-
85738574
if (parentCell==goalCell) {
85748575
Int cost = parentCell->getTotalCost();
85758576
m_isTunneling = false;
85768577
parentCell->releaseInfo();
85778578
cleanOpenAndClosedLists();
8578-
goalCell->releaseInfo();
85798579
return cost;
85808580
}
85818581

8582+
// put parent cell onto closed list - its evaluation is finished
8583+
m_closedList = parentCell->putOnClosedList( m_closedList );
8584+
85828585
if (cellCount > MAX_CELL_COUNT) {
85838586
continue;
85848587
}
@@ -8639,8 +8642,11 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86398642

86408643
if (!newCell->allocateInfo(newCellCoord)) {
86418644
// Out of cells for pathing...
8645+
parentCell->releaseInfo();
8646+
cleanOpenAndClosedLists();
8647+
goalCell->releaseInfo();
86428648
return cellCount;
8643-
}
8649+
}
86448650
cellCount++;
86458651

86468652
newCostSoFar = newCell->costSoFar( parentCell );
@@ -8826,6 +8832,7 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88268832
if (parentCell!=goalCell) {
88278833
worldToCell(&clipFrom, &pos2d);
88288834
if (!parentCell->allocateInfo(pos2d)) {
8835+
goalCell->releaseInfo();
88298836
return NULL;
88308837
}
88318838
}
@@ -9121,13 +9128,11 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
91219128
prevCell = cell;
91229129
}
91239130

9124-
if (cell->hasInfo()) {
9125-
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9126-
if (goalCellNull) {
9127-
// Very short path.
9128-
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9129-
path->prependNode( &pos, cell->getLayer() );
9130-
}
9131+
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9132+
if (goalCellNull) {
9133+
// Very short path.
9134+
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9135+
path->prependNode( &pos, cell->getLayer() );
91319136
}
91329137

91339138
// put actual start position as first node on the path, so it begins right at the unit's feet
@@ -10528,14 +10533,14 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1052810533
}
1052910534
if (startNode == originalPath->getLastNode()) {
1053010535
parentCell->releaseInfo();
10531-
cleanOpenAndClosedLists();
1053210536
return NULL; // no open nodes.
1053310537
}
1053410538
PathfindCell *candidateGoal;
1053510539
candidateGoal = getCell(LAYER_GROUND, &goalPos); // just using for cost estimates.
1053610540
ICoord2D goalCellNdx;
1053710541
worldToCell(&goalPos, &goalCellNdx);
1053810542
if (!candidateGoal->allocateInfo(goalCellNdx)) {
10543+
parentCell->releaseInfo();
1053910544
return NULL;
1054010545
}
1054110546

0 commit comments

Comments
 (0)