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.

EDIT: Made a small addition to add an extra bit of requested debug output, the failover message now also mentions the frame the failover occurred.


Map and reproduction replays compatible with Visual Studio builds
Note that these replays will mismatch at the crash point due to inital crash catch and prevention code during replay capture.

Replays: pathfinding_crash_repros.zip

@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.

Comment thread Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp Outdated
@Caball009
Caball009 self-requested a review August 12, 2026 18:32
@Mauller
Mauller force-pushed the Mauller/fix-retail-pathfinder-crashes branch 2 times, most recently from 4ddc8a3 to ee6c4f5 Compare August 12, 2026 18:36
Comment thread Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp Outdated

@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. Changes to function Pathfinder::forceCleanCells improving the printing.

@Mauller
Mauller force-pushed the Mauller/fix-retail-pathfinder-crashes branch from ee6c4f5 to dbc8b9d Compare August 13, 2026 19:19
@Mauller

Mauller commented Aug 13, 2026

Copy link
Copy Markdown
Author

Made updates to remove the failover and cleanup flags, they weren't necessary.

The only reason the reproduction replays were mismatching is due to code Cabal had added to get past the crash point.

@Mauller
Mauller force-pushed the Mauller/fix-retail-pathfinder-crashes branch from dbc8b9d to c0fc2b6 Compare August 13, 2026 19:43

@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.

Nice to see these pathfinding crashes fixed.

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