Skip to content

bugfix(pathfinder): Fix rare retail pathfinding crashes in forwardInsertionSortRetailCompatible() and putOnClosedList() - #3113

Open
Mauller wants to merge 2 commits into
TheSuperHackers:mainfrom
Mauller:Mauller/fix-retail-pathfinder-crashes
Open

bugfix(pathfinder): Fix rare retail pathfinding crashes in forwardInsertionSortRetailCompatible() and putOnClosedList()#3113
Mauller wants to merge 2 commits into
TheSuperHackers:mainfrom
Mauller:Mauller/fix-retail-pathfinder-crashes

Conversation

@Mauller

@Mauller Mauller commented Aug 11, 2026

Copy link
Copy Markdown

Closes: #2799
Closes: #2637

This PR fixes a recently discovered, but rarer to happen, pair of retail pathfinding crashes.
These crashes do not occur in the non-retail crash-fixed pathfinding.

The crash in putOnClosedList() occurs due to a pathfinding cell being placed onto the closed list without an associated pathfindCellinfo.

The retail insertion sort crash occurs for a similar reason, a cell placed onto the list contains a pathfind info that has a dangling nextOpen pointer to another cell info that is malformed.

@Mauller Mauller self-assigned this Aug 11, 2026
@Mauller Mauller added Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Crash This is a crash, very bad labels Aug 11, 2026
@Mauller
Mauller force-pushed the Mauller/fix-retail-pathfinder-crashes branch 2 times, most recently from a201f76 to 4679cb1 Compare August 11, 2026 21:24
@Mauller

Mauller commented Aug 11, 2026

Copy link
Copy Markdown
Author

Just a small wording tweak that i noticed.

@Mauller Mauller changed the title bugfix(pathfinding): Fix rare retail pathfinding crashes in forwardInsertionSortRetailCompatible() and putOnClosedList() bugfix(pathfinder): Fix rare retail pathfinding crashes in forwardInsertionSortRetailCompatible() and putOnClosedList() Aug 11, 2026
Comment thread Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp Outdated
@@ -1727,6 +1727,15 @@ void PathfindCell::forwardInsertionSortRetailCompatible(PathfindCellList& list)
UnsignedInt cellCount = 0;
while (currentCell && cellCount < PATHFIND_CELLS_PER_FRAME && currentCell->m_info->m_totalCost <= m_info->m_totalCost)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can currentCell->m_info be null here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in the way you are likely thinking.

When cells are initially put onto the list they are externally checked to make sure they have info allocated to them first.

The only time it crashes at this point is if a cell initially put onto the list has dangling next pointers.

while (currentCell && cellCount < PATHFIND_CELLS_PER_FRAME && currentCell->m_info->m_totalCost <= m_info->m_totalCost)
{
// Prevent a retail crash where a pathfindCell has an m_info with a dangling nextOpen pointer
if (currentCell->m_info->m_nextOpen && !currentCell->m_info->m_nextOpen->m_cell->m_info) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can m_cell be null here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally when these cell infos have dangling pointers it tends to be present.

currentCell->m_info->m_nextOpen->m_cell = nullptr;
currentCell->m_info->m_nextOpen = nullptr;

s_useFixedPathfinding = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switches to fixed pathfinding but continues the current search on lists even if they're broken retail ones - could subsequent fixed sorting can consume a stale tail?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pathfinding crash that hits this point will likely bail after this point due to running out of pathfinding resources.
The pathfinding will be in a fudged state and it doesn't really matter if the list is a mess.

I don't usually like to toggle these flags unless it's in a cleaner part of the code, but not toggling them actually causes the replays to mismatch.

@Caball009
Caball009 self-requested a review August 12, 2026 18:32
@Mauller
Mauller force-pushed the Mauller/fix-retail-pathfinder-crashes branch from 4679cb1 to 4ddc8a3 Compare August 12, 2026 18:33
@Mauller
Mauller force-pushed the Mauller/fix-retail-pathfinder-crashes branch from 4ddc8a3 to ee6c4f5 Compare August 12, 2026 18:36
while (currentCell && cellCount < PATHFIND_CELLS_PER_FRAME && currentCell->m_info->m_totalCost <= m_info->m_totalCost)
{
// Prevent a retail crash where a pathfindCell has an m_info with a dangling nextOpen pointer
if (currentCell->m_info->m_nextOpen && !currentCell->m_info->m_nextOpen->m_cell->m_info) {

@Caball009 Caball009 Aug 13, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: { on new line for consistency with the code around it.

@Caball009 Caball009 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to do some testing before this gets merged.

Edit: just so I don't lose track of the desired changes:

  1. Removal of the failover code for these fixes because they're not necessary for the (VC6) replays.
  2. Attaching the VS22 reproduction replays & custom map to the PR description.
  3. Proposed changes to Pathfinder::forceCleanCells improving the printing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Crash This is a crash, very bad Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Game crashes in pathfinding code in function PathfindCell::forwardInsertionSortRetailCompatible Replay crashes on pathfinding

4 participants