bugfix(pathfinder): Improve initialization of uninitialized variable in Pathfinder::classifyFence#2460
Merged
xezon merged 4 commits intoTheSuperHackers:mainfrom Mar 23, 2026
Conversation
Mauller
reviewed
Mar 18, 2026
abf7ddb to
749e6e0
Compare
Mauller
reviewed
Mar 20, 2026
c1d3957 to
0d06c98
Compare
0d06c98 to
3a17508
Compare
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Include/GameLogic/AIPathfind.h | Adds m_classifyFenceZeroInit member (guarded by RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC) exposed via an inserted public: section; uses #pragma once correctly; license header intact. |
| Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp | Replaces the previous single-value hardcoded initialization (253961804 / 4202797) with a conditional branch that uses 0,0 (zero-init path) or 1000000,1000000 (large-value path) depending on m_classifyFenceZeroInit; resets the flag to false in Pathfinder::reset(). |
| GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp | Sets m_classifyFenceZeroInit = true before the first object is destroyed (mirroring the zero-initialised stack state from PartitionManager::update) and resets it to false after each deletion so subsequent objects use the large-value path. |
Sequence Diagram
sequenceDiagram
participant PU as PartitionManager::update
participant GL as GameLogic::processDestroyList
participant PF as Pathfinder
participant CF as classifyFence
PU->>PU: zero-initialises >20K of stack memory
GL->>PF: m_classifyFenceZeroInit = true (if list non-empty)
loop For each object in destroy list
GL->>GL: Object::friend_deleteInstance(currentObject)
Note over GL: Object destructor may trigger classifyFence
GL-->>CF: (indirect) classifyFence(obj, insert)
alt m_classifyFenceZeroInit == true (first object)
CF->>CF: cellBounds.hi = {0, 0}
else m_classifyFenceZeroInit == false (subsequent objects)
CF->>CF: cellBounds.hi = {1000000, 1000000}
end
GL->>PF: m_classifyFenceZeroInit = false
end
GL->>GL: m_objectsToDestroy.clear()
Prompt To Fix All With AI
This is a comment left during a code review.
Path: Core/GameEngine/Include/GameLogic/AIPathfind.h
Line: 908-911
Comment:
**Public member breaks class encapsulation**
Inserting a `public:` specifier inside what is otherwise a `private:` section to expose `m_classifyFenceZeroInit` is a workaround that breaks encapsulation. Any code (not just `GameLogic::processDestroyList`) can freely read/write this state, and the naming convention (`m_` prefix) signals it should be private implementation detail.
Consider providing a dedicated setter (or a friend declaration) instead:
```cpp
#if RTS_ZEROHOUR && RETAIL_COMPATIBLE_CRC
void setClassifyFenceZeroInit(Bool value) { m_classifyFenceZeroInit = value; }
private:
Bool m_classifyFenceZeroInit;
#endif
```
This keeps the data private while still allowing `GameLogic::processDestroyList` to call the setter.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
Line: 2493
Comment:
**Comment slightly misrepresents when the flag is reset**
The comment says "It's set to false when this function exits," but `m_classifyFenceZeroInit` is actually reset to `false` *inside the loop* — immediately after each object is deleted (line 2558). This means all objects after the first are processed with `m_classifyFenceZeroInit = false` (large-value mode), not just at exit. The comment could be clearer about this behaviour to prevent future readers from assuming the flag stays `true` for the entire loop.
```suggestion
// TheSuperHackers @info Set m_classifyFenceZeroInit to true for the first object. It's reset to false after each object is deleted.
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "Tweaked comments."
xezon
approved these changes
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
( the link is broken on purpose so it doesn't link, because I may close this draft PR if it doesn't work out )
This PR makes a small change to the initialization of the previously uninitialized variable in
Pathfinder::classifyFence. I saw 4 places where the game eventually callsPathfinder::classifyFencefor maps with fences:GameLogic::startNewGameGameLogic::processDestroyListToppleUpdate::applyTopplingForceGameLogic::processDestroyListI noticed there's an initialization pattern that the game appears to follow for the most part. The uninitialized values tend to be either very large (> 100'000) or 0.
GameLogic::processDestroyListruns directly afterPartitionManager::updatewhich zero initializes > 20K of memory on the stack. This sets the uninitialized variables that are used inPathfinder::classifyFenceto 0, and they usually stay 0.I also noticed that the destruction of an object drawable can modify the values as well, which is why the zero initialization is disabled after the first destroyed object. Naturally, there's no way to come up with a complete fix due to the nature of the issue, but the new initialization does fix the mismatches in these two replays:
fixed_replays.zip
I have four replays in total that mismatch because of the uninitialized variable; two are fixed with this change, and two continue to mismatch:
mm_replays.zip
TODO: