Skip to content

Commit e38dcf3

Browse files
Maullerroossienb
andcommitted
[ZH] Reduce crashing within AIPathfind due to inadequate pathing resource cleanup and null pathing info within some cells.
Co-authored-by: Bart Roossien <roossienb@users.noreply.github.com>
1 parent 42d5c3a commit e38dcf3

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

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

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6646,6 +6646,7 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
66466646
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, false );
66476647
parentCell->releaseInfo();
66486648
cleanOpenAndClosedLists();
6649+
goalCell->releaseInfo();
66496650
return path;
66506651
}
66516652

@@ -6722,8 +6723,9 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
67226723
#endif
67236724

67246725
m_isTunneling = false;
6725-
goalCell->releaseInfo();
6726+
parentCell->releaseInfo();
67266727
cleanOpenAndClosedLists();
6728+
goalCell->releaseInfo();
67276729
return NULL;
67286730
}
67296731

@@ -7158,6 +7160,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71587160
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
71597161
parentCell->releaseInfo();
71607162
cleanOpenAndClosedLists();
7163+
goalCell->releaseInfo();
71617164
return path;
71627165
}
71637166

@@ -7352,8 +7355,9 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
73527355
TheGameLogic->incrementOverallFailedPathfinds();
73537356
#endif
73547357
m_isTunneling = false;
7355-
goalCell->releaseInfo();
7358+
parentCell->releaseInfo();
73567359
cleanOpenAndClosedLists();
7360+
goalCell->releaseInfo();
73577361
return NULL;
73587362
}
73597363

@@ -7731,11 +7735,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
77317735
#endif
77327736
}
77337737
#endif
7734-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
7735-
goalCell->releaseInfo();
7736-
}
77377738
parentCell->releaseInfo();
77387739
cleanOpenAndClosedLists();
7740+
goalCell->releaseInfo();
77397741
return path;
77407742
}
77417743

@@ -7932,10 +7934,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79327934
}
79337935
#endif
79347936
#endif
7935-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
7936-
goalCell->releaseInfo();
7937-
}
7937+
parentCell->releaseInfo();
79387938
cleanOpenAndClosedLists();
7939+
goalCell->releaseInfo();
79397940
return path;
79407941
}
79417942

@@ -7982,8 +7983,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79827983
TheGameLogic->incrementOverallFailedPathfinds();
79837984
#endif
79847985
m_isTunneling = false;
7985-
goalCell->releaseInfo();
7986+
parentCell->releaseInfo();
79867987
cleanOpenAndClosedLists();
7988+
goalCell->releaseInfo();
79877989
return NULL;
79887990
}
79897991

@@ -8418,6 +8420,7 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
84188420
}
84198421
#endif
84208422
m_isTunneling = false;
8423+
parentCell->releaseInfo();
84218424
cleanOpenAndClosedLists();
84228425
goalCell->releaseInfo();
84238426
return false;
@@ -8551,7 +8554,9 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85518554
if (parentCell==goalCell) {
85528555
Int cost = parentCell->getTotalCost();
85538556
m_isTunneling = false;
8557+
parentCell->releaseInfo();
85548558
cleanOpenAndClosedLists();
8559+
goalCell->releaseInfo();
85558560
return cost;
85568561
}
85578562

@@ -8663,10 +8668,9 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86638668
}
86648669

86658670
m_isTunneling = false;
8666-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
8667-
goalCell->releaseInfo();
8668-
}
8671+
parentCell->releaseInfo();
86698672
cleanOpenAndClosedLists();
8673+
goalCell->releaseInfo();
86708674
return MAX_COST;
86718675
}
86728676

@@ -8869,8 +8873,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88698873
// construct and return path
88708874
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, blocked);
88718875
parentCell->releaseInfo();
8872-
goalCell->releaseInfo();
88738876
cleanOpenAndClosedLists();
8877+
goalCell->releaseInfo();
88748878
return path;
88758879
}
88768880
// put parent cell onto closed list - its evaluation is finished
@@ -8950,8 +8954,9 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89508954
rawTo->y = closesetCell->getYIndex()*PATHFIND_CELL_SIZE_F + PATHFIND_CELL_SIZE_F/2.0f;
89518955
// construct and return path
89528956
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, closesetCell, centerInCell, blocked );
8953-
goalCell->releaseInfo();
8957+
parentCell->releaseInfo();
89548958
cleanOpenAndClosedLists();
8959+
goalCell->releaseInfo();
89558960
return path;
89568961
}
89578962

@@ -8972,8 +8977,9 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89728977
TheGameLogic->incrementOverallFailedPathfinds();
89738978
#endif
89748979
m_isTunneling = false;
8975-
goalCell->releaseInfo();
8980+
parentCell->releaseInfo();
89768981
cleanOpenAndClosedLists();
8982+
goalCell->releaseInfo();
89778983
return NULL;
89788984
}
89798985

@@ -9095,12 +9101,16 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
90959101
}
90969102
prevCell = cell;
90979103
}
9098-
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9099-
if (goalCellNull) {
9100-
// Very short path.
9101-
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9102-
path->prependNode( &pos, cell->getLayer() );
9104+
9105+
if (cell->hasInfo()) {
9106+
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9107+
if (goalCellNull) {
9108+
// Very short path.
9109+
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9110+
path->prependNode( &pos, cell->getLayer() );
9111+
}
91039112
}
9113+
91049114
// put actual start position as first node on the path, so it begins right at the unit's feet
91059115
if (fromPos->x != path->getFirstNode()->getPosition()->x || fromPos->y != path->getFirstNode()->getPosition()->y) {
91069116
path->prependNode( fromPos, cell->getLayer() );
@@ -10381,6 +10391,7 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1038110391
DEBUG_LOG(("Unit '%s', time %f\n", obj->getTemplate()->getName().str(), (::GetTickCount()-startTimeMS)/1000.0f));
1038210392

1038310393
m_isTunneling = false;
10394+
parentCell->releaseInfo();
1038410395
cleanOpenAndClosedLists();
1038510396
return NULL;
1038610397
}
@@ -10497,6 +10508,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1049710508

1049810509
}
1049910510
if (startNode == originalPath->getLastNode()) {
10511+
parentCell->releaseInfo();
1050010512
cleanOpenAndClosedLists();
1050110513
return NULL; // no open nodes.
1050210514
}
@@ -10565,12 +10577,9 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1056510577
}
1056610578
#endif
1056710579
m_isTunneling = false;
10568-
if (!candidateGoal->getOpen() && !candidateGoal->getClosed())
10569-
{
10570-
// Not on one of the lists
10571-
candidateGoal->releaseInfo();
10572-
}
10580+
parentCell->releaseInfo();
1057310581
cleanOpenAndClosedLists();
10582+
candidateGoal->releaseInfo();
1057410583
return NULL;
1057510584
}
1057610585

@@ -10863,10 +10872,9 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1086310872
}
1086410873
}
1086510874
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10866-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
10867-
goalCell->releaseInfo();
10868-
}
10875+
parentCell->releaseInfo();
1086910876
cleanOpenAndClosedLists();
10877+
goalCell->releaseInfo();
1087010878
return path;
1087110879
}
1087210880
}
@@ -10923,10 +10931,9 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1092310931
TheGameLogic->incrementOverallFailedPathfinds();
1092410932
#endif
1092510933
m_isTunneling = false;
10926-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
10927-
goalCell->releaseInfo();
10928-
}
10934+
parentCell->releaseInfo();
1092910935
cleanOpenAndClosedLists();
10936+
goalCell->releaseInfo();
1093010937
return NULL;
1093110938
}
1093210939

@@ -11084,6 +11091,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1108411091
TheGameLogic->incrementOverallFailedPathfinds();
1108511092
#endif
1108611093
m_isTunneling = false;
11094+
parentCell->releaseInfo();
1108711095
cleanOpenAndClosedLists();
1108811096
return NULL;
1108911097
}

0 commit comments

Comments
 (0)