Skip to content

Commit add0ba6

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 e83038f commit add0ba6

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
@@ -6650,6 +6650,7 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
66506650
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, false );
66516651
parentCell->releaseInfo();
66526652
cleanOpenAndClosedLists();
6653+
goalCell->releaseInfo();
66536654
return path;
66546655
}
66556656

@@ -6726,8 +6727,9 @@ Path *Pathfinder::internalFindPath( Object *obj, const LocomotorSet& locomotorSe
67266727
#endif
67276728

67286729
m_isTunneling = false;
6729-
goalCell->releaseInfo();
6730+
parentCell->releaseInfo();
67306731
cleanOpenAndClosedLists();
6732+
goalCell->releaseInfo();
67316733
return NULL;
67326734
}
67336735

@@ -7167,6 +7169,7 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71677169
Path *path = buildGroundPath(crusher, from, goalCell, centerInCell, pathDiameter );
71687170
parentCell->releaseInfo();
71697171
cleanOpenAndClosedLists();
7172+
goalCell->releaseInfo();
71707173
return path;
71717174
}
71727175

@@ -7371,8 +7374,9 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
73717374
TheGameLogic->incrementOverallFailedPathfinds();
73727375
#endif
73737376
m_isTunneling = false;
7374-
goalCell->releaseInfo();
7377+
parentCell->releaseInfo();
73757378
cleanOpenAndClosedLists();
7379+
goalCell->releaseInfo();
73767380
return NULL;
73777381
}
73787382

@@ -7750,11 +7754,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
77507754
#endif
77517755
}
77527756
#endif
7753-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
7754-
goalCell->releaseInfo();
7755-
}
77567757
parentCell->releaseInfo();
77577758
cleanOpenAndClosedLists();
7759+
goalCell->releaseInfo();
77587760
return path;
77597761
}
77607762

@@ -7951,10 +7953,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
79517953
}
79527954
#endif
79537955
#endif
7954-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
7955-
goalCell->releaseInfo();
7956-
}
7956+
parentCell->releaseInfo();
79577957
cleanOpenAndClosedLists();
7958+
goalCell->releaseInfo();
79587959
return path;
79597960
}
79607961

@@ -8001,8 +8002,9 @@ Path *Pathfinder::internal_findHierarchicalPath( Bool isHuman, const LocomotorSu
80018002
TheGameLogic->incrementOverallFailedPathfinds();
80028003
#endif
80038004
m_isTunneling = false;
8004-
goalCell->releaseInfo();
8005+
parentCell->releaseInfo();
80058006
cleanOpenAndClosedLists();
8007+
goalCell->releaseInfo();
80068008
return NULL;
80078009
}
80088010

@@ -8437,6 +8439,7 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
84378439
}
84388440
#endif
84398441
m_isTunneling = false;
8442+
parentCell->releaseInfo();
84408443
cleanOpenAndClosedLists();
84418444
goalCell->releaseInfo();
84428445
return false;
@@ -8570,7 +8573,9 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85708573
if (parentCell==goalCell) {
85718574
Int cost = parentCell->getTotalCost();
85728575
m_isTunneling = false;
8576+
parentCell->releaseInfo();
85738577
cleanOpenAndClosedLists();
8578+
goalCell->releaseInfo();
85748579
return cost;
85758580
}
85768581

@@ -8682,10 +8687,9 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
86828687
}
86838688

86848689
m_isTunneling = false;
8685-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
8686-
goalCell->releaseInfo();
8687-
}
8690+
parentCell->releaseInfo();
86888691
cleanOpenAndClosedLists();
8692+
goalCell->releaseInfo();
86898693
return MAX_COST;
86908694
}
86918695

@@ -8888,8 +8892,8 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
88888892
// construct and return path
88898893
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, goalCell, centerInCell, blocked);
88908894
parentCell->releaseInfo();
8891-
goalCell->releaseInfo();
88928895
cleanOpenAndClosedLists();
8896+
goalCell->releaseInfo();
88938897
return path;
88948898
}
88958899
// put parent cell onto closed list - its evaluation is finished
@@ -8969,8 +8973,9 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89698973
rawTo->y = closesetCell->getYIndex()*PATHFIND_CELL_SIZE_F + PATHFIND_CELL_SIZE_F/2.0f;
89708974
// construct and return path
89718975
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), from, closesetCell, centerInCell, blocked );
8972-
goalCell->releaseInfo();
8976+
parentCell->releaseInfo();
89738977
cleanOpenAndClosedLists();
8978+
goalCell->releaseInfo();
89748979
return path;
89758980
}
89768981

@@ -8991,8 +8996,9 @@ Path *Pathfinder::findClosestPath( Object *obj, const LocomotorSet& locomotorSet
89918996
TheGameLogic->incrementOverallFailedPathfinds();
89928997
#endif
89938998
m_isTunneling = false;
8994-
goalCell->releaseInfo();
8999+
parentCell->releaseInfo();
89959000
cleanOpenAndClosedLists();
9001+
goalCell->releaseInfo();
89969002
return NULL;
89979003
}
89989004

@@ -9114,12 +9120,16 @@ void Pathfinder::prependCells( Path *path, const Coord3D *fromPos,
91149120
}
91159121
prevCell = cell;
91169122
}
9117-
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9118-
if (goalCellNull) {
9119-
// Very short path.
9120-
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9121-
path->prependNode( &pos, cell->getLayer() );
9123+
9124+
if (cell->hasInfo()) {
9125+
m_zoneManager.setPassable(cell->getXIndex(), cell->getYIndex(), true);
9126+
if (goalCellNull) {
9127+
// Very short path.
9128+
adjustCoordToCell(cell->getXIndex(), cell->getYIndex(), center, pos, cell->getLayer());
9129+
path->prependNode( &pos, cell->getLayer() );
9130+
}
91229131
}
9132+
91239133
// put actual start position as first node on the path, so it begins right at the unit's feet
91249134
if (fromPos->x != path->getFirstNode()->getPosition()->x || fromPos->y != path->getFirstNode()->getPosition()->y) {
91259135
path->prependNode( fromPos, cell->getLayer() );
@@ -10400,6 +10410,7 @@ Path *Pathfinder::getMoveAwayFromPath(Object* obj, Object *otherObj,
1040010410
DEBUG_LOG(("Unit '%s', time %f\n", obj->getTemplate()->getName().str(), (::GetTickCount()-startTimeMS)/1000.0f));
1040110411

1040210412
m_isTunneling = false;
10413+
parentCell->releaseInfo();
1040310414
cleanOpenAndClosedLists();
1040410415
return NULL;
1040510416
}
@@ -10516,6 +10527,7 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1051610527

1051710528
}
1051810529
if (startNode == originalPath->getLastNode()) {
10530+
parentCell->releaseInfo();
1051910531
cleanOpenAndClosedLists();
1052010532
return NULL; // no open nodes.
1052110533
}
@@ -10584,12 +10596,9 @@ Path *Pathfinder::patchPath( const Object *obj, const LocomotorSet& locomotorSet
1058410596
}
1058510597
#endif
1058610598
m_isTunneling = false;
10587-
if (!candidateGoal->getOpen() && !candidateGoal->getClosed())
10588-
{
10589-
// Not on one of the lists
10590-
candidateGoal->releaseInfo();
10591-
}
10599+
parentCell->releaseInfo();
1059210600
cleanOpenAndClosedLists();
10601+
candidateGoal->releaseInfo();
1059310602
return NULL;
1059410603
}
1059510604

@@ -10882,10 +10891,9 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1088210891
}
1088310892
}
1088410893
Path *path = buildActualPath( obj, locomotorSet.getValidSurfaces(), obj->getPosition(), parentCell, centerInCell, false);
10885-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
10886-
goalCell->releaseInfo();
10887-
}
10894+
parentCell->releaseInfo();
1088810895
cleanOpenAndClosedLists();
10896+
goalCell->releaseInfo();
1088910897
return path;
1089010898
}
1089110899
}
@@ -10942,10 +10950,9 @@ Path *Pathfinder::findAttackPath( const Object *obj, const LocomotorSet& locomot
1094210950
TheGameLogic->incrementOverallFailedPathfinds();
1094310951
#endif
1094410952
m_isTunneling = false;
10945-
if (goalCell->hasInfo() && !goalCell->getClosed() && !goalCell->getOpen()) {
10946-
goalCell->releaseInfo();
10947-
}
10953+
parentCell->releaseInfo();
1094810954
cleanOpenAndClosedLists();
10955+
goalCell->releaseInfo();
1094910956
return NULL;
1095010957
}
1095110958

@@ -11103,6 +11110,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1110311110
TheGameLogic->incrementOverallFailedPathfinds();
1110411111
#endif
1110511112
m_isTunneling = false;
11113+
parentCell->releaseInfo();
1110611114
cleanOpenAndClosedLists();
1110711115
return NULL;
1110811116
}

0 commit comments

Comments
 (0)