Skip to content

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

Draft
Caball009 wants to merge 1 commit intoTheSuperHackers:mainfrom
Caball009:fix_Pathfinder_tightenPathCallback_variable
Draft

bugfix(pathfinder): Fix uninitialized variable in Pathfinder::tightenPathCallback to prevent mismatches#2309
Caball009 wants to merge 1 commit 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. The fix cannot be applied unconditionally, because it breaks the golden replay 1 and probably others. It's currently tied to the path-finding fail-over, because that's better than nothing. It needs to be replaced with a proper opt-in mechanism. Adding this fix should be good for GeneralsOnline.

Edit: maybe some other values will work well enough that we can use them for retail.

TODO:

  • Maybe test different values for retail fix.
  • 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 Overview

Greptile Summary

Fixed an uninitialized variable bug in Pathfinder::tightenPathCallback that caused mismatches when units drove on terrain near certain bridges. The pos variable is now properly initialized by calling adjustCoordToCell before being passed to checkForAdjust.

  • Made adjustCoordToCell static to allow calling from the static tightenPathCallback function
  • Added initialization of the pos variable with conditional compilation guard RETAIL_COMPATIBLE_PATHFINDING and runtime check s_useFixedPathfinding
  • The fix is gated behind the pathfinding fail-over mechanism to avoid breaking golden replays

The workaround is documented as incomplete and needs replacement with a proper opt-in mechanism in the future.

Confidence Score: 4/5

  • This PR is safe to merge with low risk - fixes a legitimate uninitialized variable bug
  • The fix properly addresses an uninitialized variable that was causing deterministic mismatches. The implementation is conservative with conditional compilation guards and runtime checks to preserve retail compatibility. The workaround nature is well-documented and the static method change is necessary and safe.
  • No files require special attention

Important Files Changed

Filename Overview
Generals/Code/GameEngine/Include/GameLogic/AIPathfind.h Made adjustCoordToCell static to allow calling from static callback function
Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp Initialized uninitialized pos variable in tightenPathCallback using conditional compilation guard, implemented function as static

Last reviewed commit: 1d78179

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

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