Skip to content

bugfix(pathfinder): Fix uninitialized variable in Pathfinder::tightenPathCallback to prevent mismatches#2309

Open
Caball009 wants to merge 2 commits intoTheSuperHackers:mainfrom
Caball009:fix_Pathfinder_tightenPathCallback_variable
Open

bugfix(pathfinder): Fix uninitialized variable in Pathfinder::tightenPathCallback to prevent mismatches#2309
Caball009 wants to merge 2 commits intoTheSuperHackers:mainfrom
Caball009:fix_Pathfinder_tightenPathCallback_variable

Conversation

@Caball009
Copy link

@Caball009 Caball009 commented Feb 15, 2026

Another uninitialized variable rears its ugly head; this time in the path finding code. Causes mismatches, which can be reproduced by driving on the terrain around certain bridges.

Reproduction in Sand Serpent:

bridge_mm.mp4

Replay for VC6:

00-04-16_1v1_adapte_Anthony1.zip This replay does not mismatch with retail executable, and first started to mismatch with 4bbf0c0

Map and replay for VS22:

bridge_mm.zip This replay was recorded with a release build, and the mismatch shows when replay is played back with a debug build.

Notes:

I could not see any noticeable issues in-game because of this bug during my testing. I checked more than 3500 replays and this change did not introduce new mismatches. Unfortunately, the mismatch in the above replay did not go away.

TODO:

  • Replicate in Generals.

Thanks to @Mauller and @DrGoldFish1 for their help.

@Caball009 Caball009 added Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Stability Concerns stability of the runtime Bug Something is not working right, typically is user facing labels Feb 15, 2026
@greptile-apps
Copy link

greptile-apps bot commented Feb 15, 2026

Greptile Summary

Fixes an uninitialized variable pos in Pathfinder::tightenPathCallback that caused network mismatches when vehicles drive near certain bridges.

  • Initializes pos to d->destPos and zeros it if foundDest is false, matching retail's empirical behavior
  • Improves clarity of return statement comments (failure vs success but continue)
  • Well-documented with bugfix comment explaining the issue and fix date
  • Tested with 3500+ replays showing no new mismatches introduced

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Targeted bugfix for undefined behavior with clear logic, thorough testing (3500+ replays), proper documentation, and adherence to all coding standards
  • No files require special attention

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp Initializes previously uninitialized pos variable in tightenPathCallback to prevent undefined behavior and match retail determinism; clarifies return statement comments

Last reviewed commit: 51919b3

@Caball009 Caball009 added NoRetail This fix or change is not applicable with Retail game compatibility and removed NoRetail This fix or change is not applicable with Retail game compatibility labels Feb 15, 2026
@Caball009 Caball009 marked this pull request as draft February 15, 2026 03:53
@helmutbuhler
Copy link

Interesting, that commit you mentioned already caused problems earlier in #1061. I predicted there that it might cause further mismatches, and this seems like confirmation of that. Maybe we should revert #1009 and #1013, at least for VC6 builds?

@stephanmeesters
Copy link

Did you mean to do the fix in Generals/ not GeneralsMD/?

@Caball009
Copy link
Author

Did you mean to do the fix in Generals/ not GeneralsMD/?

Oops, yeah, that's silly of me. Not sure how that happened.

@Caball009 Caball009 force-pushed the fix_Pathfinder_tightenPathCallback_variable branch from 1c744fc to 52d46c5 Compare February 15, 2026 18:06
@Caball009
Copy link
Author

Interesting, that commit you mentioned already caused problems earlier in #1061. I predicted there that it might cause further mismatches, and this seems like confirmation of that. Maybe we should revert #1009 and #1013, at least for VC6 builds?

I'm not sure if that solves anything. I tried the current main branch with the wwmath.h header from 2856a23 ( the commit before 4bbf0c0 ) and the VC6 replay still mismatches.

Harmless changes anywhere can change stack layouts and introduce mismatches that hadn't been noticeable before because of uninitialized variables.

@Caball009 Caball009 force-pushed the fix_Pathfinder_tightenPathCallback_variable branch from cc871b4 to 3eb91ef Compare February 17, 2026 18:00
@Mauller
Copy link

Mauller commented Feb 21, 2026

Considering how varied the value of Pos was, from what you showed me, maybe we can't set it to anything specific but take the non retail stuff?

@Caball009
Copy link
Author

... but take the non retail stuff?

What do you mean?

@Caball009 Caball009 force-pushed the fix_Pathfinder_tightenPathCallback_variable branch from 2fa625d to da544e9 Compare February 27, 2026 19:44
@Caball009
Copy link
Author

I was able to find a way to initialize this variable without introducing new mismatches. I checked more than 3500 replays to verify that. Unfortunately, the mismatch in the original replay did not go away.

@Caball009 Caball009 marked this pull request as ready for review February 27, 2026 23:05
@Caball009 Caball009 force-pushed the fix_Pathfinder_tightenPathCallback_variable branch from d945477 to 51919b3 Compare February 28, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something is not working right, typically is user facing Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker Stability Concerns stability of the runtime ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants