Skip to content

Commit 4e77ee8

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 01bde36 commit 4e77ee8

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
}
@@ -7167,8 +7173,8 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71677173
m_isTunneling = false;
71687174
// construct and return path
71697175
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
7170-
parentCell->releaseInfo();
71717176
cleanOpenAndClosedLists();
7177+
parentCell->releaseInfo();
71727178
return path;
71737179
}
71747180

@@ -7373,8 +7379,8 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
73737379
TheGameLogic->incrementOverallFailedPathfinds();
73747380
#endif
73757381
m_isTunneling = false;
7376-
parentCell->releaseInfo();
73777382
cleanOpenAndClosedLists();
7383+
parentCell->releaseInfo();
73787384
goalCell->releaseInfo();
73797385
return NULL;
73807386
}
@@ -7753,8 +7759,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
77537759
#endif
77547760
}
77557761
#endif
7756-
parentCell->releaseInfo();
77577762
cleanOpenAndClosedLists();
7763+
parentCell->releaseInfo();
77587764
goalCell->releaseInfo();
77597765
return path;
77607766
}
@@ -7952,8 +7958,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79527958
}
79537959
#endif
79547960
#endif
7955-
parentCell->releaseInfo();
79567961
cleanOpenAndClosedLists();
7962+
parentCell->releaseInfo();
79577963
goalCell->releaseInfo();
79587964
return path;
79597965
}
@@ -8001,8 +8007,8 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
80018007
TheGameLogic->incrementOverallFailedPathfinds();
80028008
#endif
80038009
m_isTunneling = false;
8004-
parentCell->releaseInfo();
80058010
cleanOpenAndClosedLists();
8011+
parentCell->releaseInfo();
80068012
goalCell->releaseInfo();
80078013
return NULL;
80088014
}
@@ -8439,8 +8445,8 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
84398445
}
84408446
#endif
84418447
m_isTunneling = false;
8442-
parentCell->releaseInfo();
84438448
cleanOpenAndClosedLists();
8449+
parentCell->releaseInfo();
84448450
goalCell->releaseInfo();
84458451
return false;
84468452
}
@@ -8570,8 +8576,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85708576
if (parentCell==goalCell) {
85718577
Int cost = parentCell->getTotalCost();
85728578
m_isTunneling = false;
8573-
parentCell->releaseInfo();
85748579
cleanOpenAndClosedLists();
8580+
parentCell->releaseInfo();
85758581
return cost;
85768582
}
85778583

@@ -8638,8 +8644,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86388644

86398645
if (!newCell->allocateInfo(newCellCoord)) {
86408646
// Out of cells for pathing...
8641-
parentCell->releaseInfo();
86428647
cleanOpenAndClosedLists();
8648+
parentCell->releaseInfo();
86438649
goalCell->releaseInfo();
86448650
return cellCount;
86458651
}
@@ -8689,8 +8695,8 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86898695
}
86908696

86918697
m_isTunneling = false;
8692-
parentCell->releaseInfo();
86938698
cleanOpenAndClosedLists();
8699+
parentCell->releaseInfo();
86948700
goalCell->releaseInfo();
86958701
return MAX_COST;
86968702
}
@@ -8894,8 +8900,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88948900
m_isTunneling = false;
88958901
// construct and return path
88968902
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, blocked);
8897-
parentCell->releaseInfo();
88988903
cleanOpenAndClosedLists();
8904+
parentCell->releaseInfo();
88998905
goalCell->releaseInfo();
89008906
return path;
89018907
}
@@ -8976,8 +8982,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89768982
rawTo->y = closesetCell->getYIndex()*PATHFIND_CELL_SIZE_F + PATHFIND_CELL_SIZE_F/2.0f;
89778983
// construct and return path
89788984
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, closesetCell, centerInCell, blocked );
8979-
parentCell->releaseInfo();
89808985
cleanOpenAndClosedLists();
8986+
parentCell->releaseInfo();
89818987
goalCell->releaseInfo();
89828988
return path;
89838989
}
@@ -8999,8 +9005,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89999005
TheGameLogic->incrementOverallFailedPathfinds();
90009006
#endif
90019007
m_isTunneling = false;
9002-
parentCell->releaseInfo();
90039008
cleanOpenAndClosedLists();
9009+
parentCell->releaseInfo();
90049010
goalCell->releaseInfo();
90059011
return NULL;
90069012
}
@@ -9123,14 +9129,12 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
91239129
}
91249130
prevCell = cell;
91259131
}
9126-
91279132
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
91289133
if (goalCellNull) {
91299134
// Very short path.
91309135
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
91319136
path->prependNode( &pos, cell->getLayer() );
91329137
}
9133-
91349138
// put actual start position as first node on the path, so it begins right at the unit's feet
91359139
if (fromPos->x != path->getFirstNode()->getPosition()->x || fromPos->y != path->getFirstNode()->getPosition()->y) {
91369140
path->prependNode( fromPos, cell->getLayer() );
@@ -10388,8 +10392,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1038810392
m_isTunneling = false;
1038910393
// construct and return path
1039010394
Path *newPath = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10391-
parentCell->releaseInfo();
1039210395
cleanOpenAndClosedLists();
10396+
parentCell->releaseInfo();
1039310397
return newPath;
1039410398
}
1039510399
// put parent cell onto closed list - its evaluation is finished
@@ -10411,8 +10415,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1041110415
DEBUG_LOG(("Unit '%s', time %f\n", obj->getTemplate()->getName().str(), (::GetTickCount()-startTimeMS)/1000.0f));
1041210416

1041310417
m_isTunneling = false;
10414-
parentCell->releaseInfo();
1041510418
cleanOpenAndClosedLists();
10419+
parentCell->releaseInfo();
1041610420
return NULL;
1041710421
}
1041810422

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

1057210576
// cleanup the path by checking line of sight
1057310577
path->optimize(obj, locomotorSet.getValidSurfaces(), blocked);
10574-
parentCell->releaseInfo();
1057510578
cleanOpenAndClosedLists();
10579+
parentCell->releaseInfo();
1057610580
candidateGoal->releaseInfo();
1057710581

1057810582
return path;
@@ -10597,8 +10601,8 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1059710601
}
1059810602
#endif
1059910603
m_isTunneling = false;
10600-
parentCell->releaseInfo();
1060110604
cleanOpenAndClosedLists();
10605+
parentCell->releaseInfo();
1060210606
candidateGoal->releaseInfo();
1060310607
return NULL;
1060410608
}
@@ -10892,8 +10896,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1089210896
}
1089310897
}
1089410898
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10895-
parentCell->releaseInfo();
1089610899
cleanOpenAndClosedLists();
10900+
parentCell->releaseInfo();
1089710901
goalCell->releaseInfo();
1089810902
return path;
1089910903
}
@@ -10951,8 +10955,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1095110955
TheGameLogic->incrementOverallFailedPathfinds();
1095210956
#endif
1095310957
m_isTunneling = false;
10954-
parentCell->releaseInfo();
1095510958
cleanOpenAndClosedLists();
10959+
parentCell->releaseInfo();
1095610960
goalCell->releaseInfo();
1095710961
return NULL;
1095810962
}
@@ -11075,8 +11079,8 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1107511079
#endif
1107611080
// construct and return path
1107711081
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
11078-
parentCell->releaseInfo();
1107911082
cleanOpenAndClosedLists();
11083+
parentCell->releaseInfo();
1108011084
return path;
1108111085
}
1108211086

@@ -11111,8 +11115,8 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1111111115
TheGameLogic->incrementOverallFailedPathfinds();
1111211116
#endif
1111311117
m_isTunneling = false;
11114-
parentCell->releaseInfo();
1111511118
cleanOpenAndClosedLists();
11119+
parentCell->releaseInfo();
1111611120
return NULL;
1111711121
}
1111811122

0 commit comments

Comments
 (0)