Skip to content

Commit 140e180

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 de665de commit 140e180

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
}
@@ -6652,8 +6658,8 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
66526658
m_isTunneling = false;
66536659
// construct and return path
66546660
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, false );
6655-
parentCell->releaseInfo();
66566661
cleanOpenAndClosedLists();
6662+
parentCell->releaseInfo();
66576663
return path;
66586664
}
66596665

@@ -6730,8 +6736,8 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
67306736
#endif
67316737

67326738
m_isTunneling = false;
6733-
parentCell->releaseInfo();
67346739
cleanOpenAndClosedLists();
6740+
parentCell->releaseInfo();
67356741
goalCell->releaseInfo();
67366742
return NULL;
67376743
}
@@ -7171,8 +7177,8 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71717177
m_isTunneling = false;
71727178
// construct and return path
71737179
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
7174-
parentCell->releaseInfo();
71757180
cleanOpenAndClosedLists();
7181+
parentCell->releaseInfo();
71767182
return path;
71777183
}
71787184

@@ -7377,8 +7383,8 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
73777383
TheGameLogic->incrementOverallFailedPathfinds();
73787384
#endif
73797385
m_isTunneling = false;
7380-
parentCell->releaseInfo();
73817386
cleanOpenAndClosedLists();
7387+
parentCell->releaseInfo();
73827388
goalCell->releaseInfo();
73837389
return NULL;
73847390
}
@@ -7757,8 +7763,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
77577763
#endif
77587764
}
77597765
#endif
7760-
parentCell->releaseInfo();
77617766
cleanOpenAndClosedLists();
7767+
parentCell->releaseInfo();
77627768
goalCell->releaseInfo();
77637769
return path;
77647770
}
@@ -7956,8 +7962,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79567962
}
79577963
#endif
79587964
#endif
7959-
parentCell->releaseInfo();
79607965
cleanOpenAndClosedLists();
7966+
parentCell->releaseInfo();
79617967
goalCell->releaseInfo();
79627968
return path;
79637969
}
@@ -8005,8 +8011,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
80058011
TheGameLogic->incrementOverallFailedPathfinds();
80068012
#endif
80078013
m_isTunneling = false;
8008-
parentCell->releaseInfo();
80098014
cleanOpenAndClosedLists();
8015+
parentCell->releaseInfo();
80108016
goalCell->releaseInfo();
80118017
return NULL;
80128018
}
@@ -8443,8 +8449,8 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
84438449
}
84448450
#endif
84458451
m_isTunneling = false;
8446-
parentCell->releaseInfo();
84478452
cleanOpenAndClosedLists();
8453+
parentCell->releaseInfo();
84488454
goalCell->releaseInfo();
84498455
return false;
84508456
}
@@ -8574,8 +8580,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85748580
if (parentCell==goalCell) {
85758581
Int cost = parentCell->getTotalCost();
85768582
m_isTunneling = false;
8577-
parentCell->releaseInfo();
85788583
cleanOpenAndClosedLists();
8584+
parentCell->releaseInfo();
85798585
return cost;
85808586
}
85818587

@@ -8642,8 +8648,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86428648

86438649
if (!newCell->allocateInfo(newCellCoord)) {
86448650
// Out of cells for pathing...
8645-
parentCell->releaseInfo();
86468651
cleanOpenAndClosedLists();
8652+
parentCell->releaseInfo();
86478653
goalCell->releaseInfo();
86488654
return cellCount;
86498655
}
@@ -8693,8 +8699,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86938699
}
86948700

86958701
m_isTunneling = false;
8696-
parentCell->releaseInfo();
86978702
cleanOpenAndClosedLists();
8703+
parentCell->releaseInfo();
86988704
goalCell->releaseInfo();
86998705
return MAX_COST;
87008706
}
@@ -8898,8 +8904,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88988904
m_isTunneling = false;
88998905
// construct and return path
89008906
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, blocked);
8901-
parentCell->releaseInfo();
89028907
cleanOpenAndClosedLists();
8908+
parentCell->releaseInfo();
89038909
goalCell->releaseInfo();
89048910
return path;
89058911
}
@@ -8980,8 +8986,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89808986
rawTo->y = closesetCell->getYIndex()*PATHFIND_CELL_SIZE_F + PATHFIND_CELL_SIZE_F/2.0f;
89818987
// construct and return path
89828988
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, closesetCell, centerInCell, blocked );
8983-
parentCell->releaseInfo();
89848989
cleanOpenAndClosedLists();
8990+
parentCell->releaseInfo();
89858991
goalCell->releaseInfo();
89868992
return path;
89878993
}
@@ -9003,8 +9009,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
90039009
TheGameLogic->incrementOverallFailedPathfinds();
90049010
#endif
90059011
m_isTunneling = false;
9006-
parentCell->releaseInfo();
90079012
cleanOpenAndClosedLists();
9013+
parentCell->releaseInfo();
90089014
goalCell->releaseInfo();
90099015
return NULL;
90109016
}
@@ -9127,14 +9133,12 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
91279133
}
91289134
prevCell = cell;
91299135
}
9130-
91319136
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
91329137
if (goalCellNull) {
91339138
// Very short path.
91349139
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
91359140
path->prependNode( &pos, cell->getLayer() );
91369141
}
9137-
91389142
// put actual start position as first node on the path, so it begins right at the unit's feet
91399143
if (fromPos->x != path->getFirstNode()->getPosition()->x || fromPos->y != path->getFirstNode()->getPosition()->y) {
91409144
path->prependNode( fromPos, cell->getLayer() );
@@ -10392,8 +10396,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1039210396
m_isTunneling = false;
1039310397
// construct and return path
1039410398
Path *newPath = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10395-
parentCell->releaseInfo();
1039610399
cleanOpenAndClosedLists();
10400+
parentCell->releaseInfo();
1039710401
return newPath;
1039810402
}
1039910403
// put parent cell onto closed list - its evaluation is finished
@@ -10415,8 +10419,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1041510419
DEBUG_LOG(("Unit '%s', time %f\n", obj->getTemplate()->getName().str(), (::GetTickCount()-startTimeMS)/1000.0f));
1041610420

1041710421
m_isTunneling = false;
10418-
parentCell->releaseInfo();
1041910422
cleanOpenAndClosedLists();
10423+
parentCell->releaseInfo();
1042010424
return NULL;
1042110425
}
1042210426

@@ -10575,8 +10579,8 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1057510579

1057610580
// cleanup the path by checking line of sight
1057710581
path->optimize(obj, locomotorSet.getValidSurfaces(), blocked);
10578-
parentCell->releaseInfo();
1057910582
cleanOpenAndClosedLists();
10583+
parentCell->releaseInfo();
1058010584
candidateGoal->releaseInfo();
1058110585

1058210586
return path;
@@ -10601,8 +10605,8 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1060110605
}
1060210606
#endif
1060310607
m_isTunneling = false;
10604-
parentCell->releaseInfo();
1060510608
cleanOpenAndClosedLists();
10609+
parentCell->releaseInfo();
1060610610
candidateGoal->releaseInfo();
1060710611
return NULL;
1060810612
}
@@ -10896,8 +10900,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1089610900
}
1089710901
}
1089810902
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10899-
parentCell->releaseInfo();
1090010903
cleanOpenAndClosedLists();
10904+
parentCell->releaseInfo();
1090110905
goalCell->releaseInfo();
1090210906
return path;
1090310907
}
@@ -10955,8 +10959,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1095510959
TheGameLogic->incrementOverallFailedPathfinds();
1095610960
#endif
1095710961
m_isTunneling = false;
10958-
parentCell->releaseInfo();
1095910962
cleanOpenAndClosedLists();
10963+
parentCell->releaseInfo();
1096010964
goalCell->releaseInfo();
1096110965
return NULL;
1096210966
}
@@ -11079,8 +11083,8 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1107911083
#endif
1108011084
// construct and return path
1108111085
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
11082-
parentCell->releaseInfo();
1108311086
cleanOpenAndClosedLists();
11087+
parentCell->releaseInfo();
1108411088
return path;
1108511089
}
1108611090

@@ -11115,8 +11119,8 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1111511119
TheGameLogic->incrementOverallFailedPathfinds();
1111611120
#endif
1111711121
m_isTunneling = false;
11118-
parentCell->releaseInfo();
1111911122
cleanOpenAndClosedLists();
11123+
parentCell->releaseInfo();
1112011124
return NULL;
1112111125
}
1112211126

0 commit comments

Comments
 (0)