Skip to content

Conversation

@Caball009
Copy link

@Caball009 Caball009 commented Jan 12, 2026

Coord3D resultPos;
FindPositionOptions fpOptions;
fpOptions.minRadius = GameLogicRandomValueReal(m_minDistanceAFormation, m_minDistanceBFormation);
fpOptions.maxRadius = m_maxDistanceFormation;
fpOptions.flags = FPF_USE_HIGHEST_LAYER;
ThePartitionManager->findPositionAround(pos, &fpOptions, &resultPos);
doStuffToObj( debris, m_names[pick], &resultPos, mtx, orientation, sourceObj, lifetimeFrames );

This code is called for the GLA Rebel Ambush special power. resultPos remains uninitialized if findPositionAround fails (returns false), making the behavior undeterministic (i.e. may cause mismatches). This can be tested when calling the special power on a large body of water. The m_maxDistanceFormation is quite large for this special power, so it has to be a large body of water. Mountainous terrain probably also works.

For the Contra mod, this is called for the USA Air Force General special power that spawns Comanches, which has a much lower test radius so findPositionAround is more likely to fail.

TODO:

  • Replicate in Generals
  • Maybe check large number of replays and log uninitialized values

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

Based on #2095, I tested this on 1800 replays and found no mismatch.

@Caball009
Copy link
Author

Based on #2095, I tested this on 1800 replays and found no mismatch.

Thanks, that's good news.

@Caball009 Caball009 marked this pull request as ready for review January 20, 2026 10:43
@greptile-apps
Copy link

greptile-apps bot commented Jan 20, 2026

Greptile Summary

Fixed a critical determinism bug where resultPos could remain uninitialized when findPositionAround fails to find a valid spawn location (e.g., when spawning units over large water bodies or mountainous terrain). The uninitialized variable caused non-deterministic behavior leading to multiplayer mismatches.

  • Added return value check for findPositionAround in spread formation logic
  • Falls back to center position (*pos) when no valid position is found
  • Added DEBUG_CRASH warning for RETAIL_COMPATIBLE_CRC builds to alert developers when this fallback path is taken with unpatched clients
  • Resolves issue Misplaced OCL Mismatch #429 where OCL objects would spawn at unexpected locations (bottom-left of map) causing mismatches

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix correctly addresses a well-documented uninitialized variable bug by checking the return value and providing a sensible fallback. The change is minimal, focused, and follows patterns used elsewhere in the codebase. The added debug assertion helps identify potential compatibility issues without affecting release builds.
  • No files require special attention

Important Files Changed

Filename Overview
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp Fixed critical uninitialized variable bug by checking return value of findPositionAround and falling back to center position when no valid position is found

Sequence Diagram

sequenceDiagram
    participant OCL as ObjectCreationList
    participant PM as PartitionManager
    participant Obj as Debris Object
    
    OCL->>OCL: Check m_spreadFormation flag
    alt m_spreadFormation is true
        OCL->>OCL: Initialize resultPos (Coord3D)
        OCL->>OCL: Setup FindPositionOptions
        OCL->>PM: findPositionAround(pos, fpOptions, &resultPos)
        alt Position found
            PM-->>OCL: return true (resultPos set)
        else Position not found (e.g., large water body)
            PM-->>OCL: return false (resultPos uninitialized)
            Note over OCL: OLD: Use uninitialized resultPos (MISMATCH!)
            Note over OCL: NEW: Set resultPos = *pos (fallback)
            OCL->>OCL: DEBUG_CRASH warning (if RETAIL_COMPATIBLE_CRC)
        end
        OCL->>Obj: doStuffToObj(debris, name, &resultPos, ...)
    else m_spreadFormation is false
        OCL->>Obj: doStuffToObj(debris, name, pos, ...)
    end
Loading

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Looks reasonable.

Needs to be replicated in Generals.

greptile-apps[bot]

This comment was marked as off-topic.

Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

This is one of currently 3 open PRs with fixes for uninitialized variables, which come with a small risk of introducing new mismatches. These should be merged together without other PRs in between:

@Caball009
Copy link
Author

Replicated in Generals. Ready to be merged whenever the other PRs are.

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.

Misplaced OCL Mismatch

3 participants