Skip to content

Commit 12782b5

Browse files
Maullerroossienb
andcommitted
[ZH] Reorder cells cleanup so cell lists are cleared before the individual cells and add clearing of parent cell pointers when releasing pathfind cell info
Co-authored-by: Bart Roossien <roossienb@users.noreply.github.com>
1 parent c8094b2 commit 12782b5

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,12 @@ Bool PathfindCell::allocateInfo( const ICoord2D &pos )
12971297
*/
12981298
void PathfindCell::releaseInfo( void )
12991299
{
1300+
// TheSuperHackers @bugfix Mauller/SkyAero 05/06/2025 Parent cell links need clearing to prevent dangling pointers on starting points that can link them to an invalid parent cell.
1301+
// Parent cells are only cleared within Pathfinder::prependCells, so cells that do not make it onto the final path do not get their parent cell cleared.
1302+
// Cells with a special flags also do not get their pathfindinfo cleared and therefore can leave a parent cell set on a starting cell.
1303+
if (m_info) {
1304+
m_info->m_pathParent = NULL;
1305+
}
13001306
if (m_type==PathfindCell::CELL_OBSTACLE) {
13011307
return;
13021308
}
@@ -6648,8 +6654,8 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
66486654
m_isTunneling = false;
66496655
// construct and return path
66506656
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, false );
6651-
parentCell->releaseInfo();
66526657
cleanOpenAndClosedLists();
6658+
parentCell->releaseInfo();
66536659
return path;
66546660
}
66556661

@@ -6726,8 +6732,8 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
67266732
#endif
67276733

67286734
m_isTunneling = false;
6729-
parentCell->releaseInfo();
67306735
cleanOpenAndClosedLists();
6736+
parentCell->releaseInfo();
67316737
goalCell->releaseInfo();
67326738
return NULL;
67336739
}
@@ -7162,8 +7168,8 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71627168
m_isTunneling = false;
71637169
// construct and return path
71647170
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
7165-
parentCell->releaseInfo();
71667171
cleanOpenAndClosedLists();
7172+
parentCell->releaseInfo();
71677173
return path;
71687174
}
71697175

@@ -7358,8 +7364,8 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
73587364
TheGameLogic->incrementOverallFailedPathfinds();
73597365
#endif
73607366
m_isTunneling = false;
7361-
parentCell->releaseInfo();
73627367
cleanOpenAndClosedLists();
7368+
parentCell->releaseInfo();
73637369
goalCell->releaseInfo();
73647370
return NULL;
73657371
}
@@ -7738,8 +7744,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
77387744
#endif
77397745
}
77407746
#endif
7741-
parentCell->releaseInfo();
77427747
cleanOpenAndClosedLists();
7748+
parentCell->releaseInfo();
77437749
goalCell->releaseInfo();
77447750
return path;
77457751
}
@@ -7937,8 +7943,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79377943
}
79387944
#endif
79397945
#endif
7940-
parentCell->releaseInfo();
79417946
cleanOpenAndClosedLists();
7947+
parentCell->releaseInfo();
79427948
goalCell->releaseInfo();
79437949
return path;
79447950
}
@@ -7986,8 +7992,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79867992
TheGameLogic->incrementOverallFailedPathfinds();
79877993
#endif
79887994
m_isTunneling = false;
7989-
parentCell->releaseInfo();
79907995
cleanOpenAndClosedLists();
7996+
parentCell->releaseInfo();
79917997
goalCell->releaseInfo();
79927998
return NULL;
79937999
}
@@ -8424,8 +8430,8 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
84248430
}
84258431
#endif
84268432
m_isTunneling = false;
8427-
parentCell->releaseInfo();
84288433
cleanOpenAndClosedLists();
8434+
parentCell->releaseInfo();
84298435
goalCell->releaseInfo();
84308436
return false;
84318437
}
@@ -8555,8 +8561,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85558561
if (parentCell==goalCell) {
85568562
Int cost = parentCell->getTotalCost();
85578563
m_isTunneling = false;
8558-
parentCell->releaseInfo();
85598564
cleanOpenAndClosedLists();
8565+
parentCell->releaseInfo();
85608566
return cost;
85618567
}
85628568

@@ -8623,8 +8629,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86238629

86248630
if (!newCell->allocateInfo(newCellCoord)) {
86258631
// Out of cells for pathing...
8626-
parentCell->releaseInfo();
86278632
cleanOpenAndClosedLists();
8633+
parentCell->releaseInfo();
86288634
goalCell->releaseInfo();
86298635
return cellCount;
86308636
}
@@ -8674,8 +8680,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86748680
}
86758681

86768682
m_isTunneling = false;
8677-
parentCell->releaseInfo();
86788683
cleanOpenAndClosedLists();
8684+
parentCell->releaseInfo();
86798685
goalCell->releaseInfo();
86808686
return MAX_COST;
86818687
}
@@ -8879,8 +8885,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88798885
m_isTunneling = false;
88808886
// construct and return path
88818887
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, blocked);
8882-
parentCell->releaseInfo();
88838888
cleanOpenAndClosedLists();
8889+
parentCell->releaseInfo();
88848890
goalCell->releaseInfo();
88858891
return path;
88868892
}
@@ -8961,8 +8967,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89618967
rawTo->y = closesetCell->getYIndex()*PATHFIND_CELL_SIZE_F + PATHFIND_CELL_SIZE_F/2.0f;
89628968
// construct and return path
89638969
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, closesetCell, centerInCell, blocked );
8964-
parentCell->releaseInfo();
89658970
cleanOpenAndClosedLists();
8971+
parentCell->releaseInfo();
89668972
goalCell->releaseInfo();
89678973
return path;
89688974
}
@@ -8984,8 +8990,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89848990
TheGameLogic->incrementOverallFailedPathfinds();
89858991
#endif
89868992
m_isTunneling = false;
8987-
parentCell->releaseInfo();
89888993
cleanOpenAndClosedLists();
8994+
parentCell->releaseInfo();
89898995
goalCell->releaseInfo();
89908996
return NULL;
89918997
}
@@ -9108,14 +9114,12 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
91089114
}
91099115
prevCell = cell;
91109116
}
9111-
91129117
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
91139118
if (goalCellNull) {
91149119
// Very short path.
91159120
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
91169121
path->prependNode( &pos, cell->getLayer() );
91179122
}
9118-
91199123
// put actual start position as first node on the path, so it begins right at the unit's feet
91209124
if (fromPos->x != path->getFirstNode()->getPosition()->x || fromPos->y != path->getFirstNode()->getPosition()->y) {
91219125
path->prependNode( fromPos, cell->getLayer() );
@@ -10373,8 +10377,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1037310377
m_isTunneling = false;
1037410378
// construct and return path
1037510379
Path *newPath = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10376-
parentCell->releaseInfo();
1037710380
cleanOpenAndClosedLists();
10381+
parentCell->releaseInfo();
1037810382
return newPath;
1037910383
}
1038010384
// put parent cell onto closed list - its evaluation is finished
@@ -10396,8 +10400,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1039610400
DEBUG_LOG(("Unit '%s', time %f\n", obj->getTemplate()->getName().str(), (::GetTickCount()-startTimeMS)/1000.0f));
1039710401

1039810402
m_isTunneling = false;
10399-
parentCell->releaseInfo();
1040010403
cleanOpenAndClosedLists();
10404+
parentCell->releaseInfo();
1040110405
return NULL;
1040210406
}
1040310407

@@ -10556,8 +10560,8 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1055610560

1055710561
// cleanup the path by checking line of sight
1055810562
path->optimize(obj, locomotorSet.getValidSurfaces(), blocked);
10559-
parentCell->releaseInfo();
1056010563
cleanOpenAndClosedLists();
10564+
parentCell->releaseInfo();
1056110565
candidateGoal->releaseInfo();
1056210566

1056310567
return path;
@@ -10582,8 +10586,8 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1058210586
}
1058310587
#endif
1058410588
m_isTunneling = false;
10585-
parentCell->releaseInfo();
1058610589
cleanOpenAndClosedLists();
10590+
parentCell->releaseInfo();
1058710591
candidateGoal->releaseInfo();
1058810592
return NULL;
1058910593
}
@@ -10877,8 +10881,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1087710881
}
1087810882
}
1087910883
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10880-
parentCell->releaseInfo();
1088110884
cleanOpenAndClosedLists();
10885+
parentCell->releaseInfo();
1088210886
goalCell->releaseInfo();
1088310887
return path;
1088410888
}
@@ -10936,8 +10940,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1093610940
TheGameLogic->incrementOverallFailedPathfinds();
1093710941
#endif
1093810942
m_isTunneling = false;
10939-
parentCell->releaseInfo();
1094010943
cleanOpenAndClosedLists();
10944+
parentCell->releaseInfo();
1094110945
goalCell->releaseInfo();
1094210946
return NULL;
1094310947
}
@@ -11060,8 +11064,8 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1106011064
#endif
1106111065
// construct and return path
1106211066
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
11063-
parentCell->releaseInfo();
1106411067
cleanOpenAndClosedLists();
11068+
parentCell->releaseInfo();
1106511069
return path;
1106611070
}
1106711071

@@ -11096,8 +11100,8 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1109611100
TheGameLogic->incrementOverallFailedPathfinds();
1109711101
#endif
1109811102
m_isTunneling = false;
11099-
parentCell->releaseInfo();
1110011103
cleanOpenAndClosedLists();
11104+
parentCell->releaseInfo();
1110111105
return NULL;
1110211106
}
1110311107

0 commit comments

Comments
 (0)