Skip to content

Conversation

@xezon
Copy link

@xezon xezon commented Jan 25, 2026

This change fixes wrong ghost objects shown after loading a savegame.

This happened because the original Xfer code added ALL ghost objects to scene, including those that do not belong to the local player.

This issue does not happen in Retail Game, because it did not record snapshots for all players and was disabled behind the DEBUG_FOG_MEMORY macro. We enabled this functionality with #1569 so that we can track the ghost objects for all players.

I moved the fix to loadPostProcess because that is a cleaner location for it.

TODO

  • Replicate in Generals

@xezon xezon added Bug Something is not working right, typically is user facing Major Severity: Minor < Major < Critical < Blocker ThisProject The issue was introduced by this project, or this task is specific to this project labels Jan 25, 2026
@xezon
Copy link
Author

xezon commented Jan 26, 2026

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

This PR fixes a bug where wrong ghost objects were shown after loading a savegame. The issue occurred because the original code in xfer() added ALL ghost objects to the scene, including those that don't belong to the local player.

  • Removed premature addToScene() calls and removeParentObject() logic from the xfer() method
  • Moved the scene addition logic to loadPostProcess() where it's executed after all deserialization is complete
  • Added proper local player filtering by calling addToScene(playerIndex) only for the local player
  • The removeParentObject() call is now conditional on successful snapshot addition

This fix addresses issue #1923 and is a follow-up to PR #1569, which enabled ghost object tracking for all players (previously disabled behind DEBUG_FOG_MEMORY in retail).

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The changes are well-structured and address a specific bug by moving logic to a more appropriate location with proper player filtering. The identical implementation in both Generals and GeneralsMD ensures consistency.
  • No files require special attention

Important Files Changed

Filename Overview
Generals/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp Moved ghost object scene addition logic from xfer() to loadPostProcess() with proper local player filtering
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameLogic/W3DGhostObject.cpp Moved ghost object scene addition logic from xfer() to loadPostProcess() with proper local player filtering

Sequence Diagram

sequenceDiagram
    participant Save as Savegame System
    participant Xfer as Xfer (Load)
    participant Ghost as W3DGhostObject
    participant Scene as 3D Scene
    participant Parent as Parent Object

    Note over Save,Parent: Loading Savegame Process
    
    Save->>Xfer: Load savegame data
    Xfer->>Ghost: xfer(xfer)
    
    Note over Ghost: Loop through all players
    Ghost->>Ghost: Create snapshots for ALL players
    Note over Ghost: ❌ OLD: Added ALL snapshots to scene<br/>✅ NEW: Only create snapshots, don't add
    
    Xfer->>Ghost: loadPostProcess()
    Ghost->>Ghost: Get local player index
    Ghost->>Ghost: addToScene(localPlayerIndex)
    
    alt Snapshot added for local player
        Ghost->>Scene: Add local player's snapshot
        Scene-->>Ghost: Success
        Ghost->>Parent: removeParentObject()
        Note over Parent: Remove real object<br/>since ghost is visible
    else No snapshot for local player
        Note over Ghost: Keep real object in scene
    end
Loading

Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

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

Code looks good - I haven't tested it though.

@xezon
Copy link
Author

xezon commented Jan 27, 2026

Replicated in Generals without conflicts.

I did another pass on the code comment and preserved the EA comments.

@stephanmeesters
Copy link

stephanmeesters commented Jan 28, 2026

Tested with the savegame that was included in the original issue.

Apparently the building was being destroyed as the samegame happened, as can be seen by the rangers coming from it. With the fix the ghost building is gone and you see some of the rubble from the destroyed building

Before:
image

After:
Screenshot From 2026-01-28 12-50-38

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 Major Severity: Minor < Major < Critical < Blocker ThisProject The issue was introduced by this project, or this task is specific to this project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ghost buildings after loading a saved game

3 participants