Skip to content

Commit b3ffce0

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 b3ffce0

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

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

Lines changed: 28 additions & 22 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 04/05/2025 Parent cell links need clearing to prevent dangling pointers on start cells linking 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
}
@@ -10373,8 +10379,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1037310379
m_isTunneling = false;
1037410380
// construct and return path
1037510381
Path *newPath = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10376-
parentCell->releaseInfo();
1037710382
cleanOpenAndClosedLists();
10383+
parentCell->releaseInfo();
1037810384
return newPath;
1037910385
}
1038010386
// put parent cell onto closed list - its evaluation is finished
@@ -10396,8 +10402,8 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1039610402
DEBUG_LOG(("Unit '%s', time %f\n", obj->getTemplate()->getName().str(), (::GetTickCount()-startTimeMS)/1000.0f));
1039710403

1039810404
m_isTunneling = false;
10399-
parentCell->releaseInfo();
1040010405
cleanOpenAndClosedLists();
10406+
parentCell->releaseInfo();
1040110407
return NULL;
1040210408
}
1040310409

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

1055710563
// cleanup the path by checking line of sight
1055810564
path->optimize(obj, locomotorSet.getValidSurfaces(), blocked);
10559-
parentCell->releaseInfo();
1056010565
cleanOpenAndClosedLists();
10566+
parentCell->releaseInfo();
1056110567
candidateGoal->releaseInfo();
1056210568

1056310569
return path;
@@ -10582,8 +10588,8 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1058210588
}
1058310589
#endif
1058410590
m_isTunneling = false;
10585-
parentCell->releaseInfo();
1058610591
cleanOpenAndClosedLists();
10592+
parentCell->releaseInfo();
1058710593
candidateGoal->releaseInfo();
1058810594
return NULL;
1058910595
}
@@ -10877,8 +10883,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1087710883
}
1087810884
}
1087910885
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10880-
parentCell->releaseInfo();
1088110886
cleanOpenAndClosedLists();
10887+
parentCell->releaseInfo();
1088210888
goalCell->releaseInfo();
1088310889
return path;
1088410890
}
@@ -10936,8 +10942,8 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1093610942
TheGameLogic->incrementOverallFailedPathfinds();
1093710943
#endif
1093810944
m_isTunneling = false;
10939-
parentCell->releaseInfo();
1094010945
cleanOpenAndClosedLists();
10946+
parentCell->releaseInfo();
1094110947
goalCell->releaseInfo();
1094210948
return NULL;
1094310949
}
@@ -11060,8 +11066,8 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1106011066
#endif
1106111067
// construct and return path
1106211068
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
11063-
parentCell->releaseInfo();
1106411069
cleanOpenAndClosedLists();
11070+
parentCell->releaseInfo();
1106511071
return path;
1106611072
}
1106711073

@@ -11096,8 +11102,8 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1109611102
TheGameLogic->incrementOverallFailedPathfinds();
1109711103
#endif
1109811104
m_isTunneling = false;
11099-
parentCell->releaseInfo();
1110011105
cleanOpenAndClosedLists();
11106+
parentCell->releaseInfo();
1110111107
return NULL;
1110211108
}
1110311109

0 commit comments

Comments
 (0)