Skip to content

fix(update): Fix value initialization of ProjectileStreamUpdate::m_projectileIDs#2248

Merged
xezon merged 4 commits intoTheSuperHackers:mainfrom
Caball009:fix_constructor_ProjectileStreamUpdate
Feb 3, 2026
Merged

fix(update): Fix value initialization of ProjectileStreamUpdate::m_projectileIDs#2248
xezon merged 4 commits intoTheSuperHackers:mainfrom
Caball009:fix_constructor_ProjectileStreamUpdate

Conversation

@Caball009
Copy link

@Caball009 Caball009 commented Feb 3, 2026

This PR properly initializes ProjectileStreamUpdate::m_projectileIDs instead of a local array with the same name. This change is not user-facing because the memory allocators would still zero-initialize memory on allocation. I've also reordered the assignments to match the order of declaration.

This class is used for the GLA Toxin Tractor and USA Ambulance on the first time they fire, and on loading a save game with these units if they have fired before.

TODO:

  • Replicate in Generals.

@Caball009 Caball009 added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Fix Is fixing something, but is not user facing Stability Concerns stability of the runtime labels Feb 3, 2026
@greptile-apps
Copy link

greptile-apps bot commented Feb 3, 2026

Greptile Overview

Greptile Summary

Fixed a critical variable shadowing bug in ProjectileStreamUpdate constructor where a local array was being initialized instead of the member variable m_projectileIDs. The old code declared ObjectID m_projectileIDs[MAX_PROJECTILE_STREAM] as a local variable, shadowing the class member, which left the actual member array uninitialized.

Changes:

  • Replaced manual loop with std::fill() to correctly initialize the member m_projectileIDs array with INVALID_ID
  • Reordered member initialization to match declaration order in header file
  • Applied identical fix to both Generals and GeneralsMD versions

Impact:
While the bug was masked in practice by zero-initialization from memory allocators, this fix eliminates undefined behavior and ensures proper initialization. Affects GLA Toxin Tractor and USA Ambulance projectile stream rendering on first fire and save game loading.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The fix correctly addresses a variable shadowing bug by properly initializing the member array instead of a local variable. The use of std::fill is idiomatic C++, and the reordering of initialization matches the declaration order. Both files (Generals and GeneralsMD) have identical, correct fixes.
  • No files require special attention

Important Files Changed

Filename Overview
Generals/Code/GameEngine/Source/GameLogic/Object/Update/ProjectileStreamUpdate.cpp Fixed variable shadowing bug by properly initializing member m_projectileIDs array using std::fill, and reordered member initialization to match declaration order
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProjectileStreamUpdate.cpp Fixed variable shadowing bug by properly initializing member m_projectileIDs array using std::fill, and reordered member initialization to match declaration order

Sequence Diagram

sequenceDiagram
    participant Client as Game System
    participant Constructor as ProjectileStreamUpdate()
    participant Member as m_projectileIDs[20]
    
    Note over Client,Member: Before Fix - Variable Shadowing Bug
    Client->>Constructor: new ProjectileStreamUpdate()
    Constructor->>Constructor: ObjectID m_projectileIDs[20] (local)
    Constructor->>Constructor: for loop initializes local array
    Note over Constructor: Local array destroyed!
    Constructor->>Member: Member array left uninitialized
    Constructor-->>Client: Return (undefined behavior)
    
    Note over Client,Member: After Fix - Correct Initialization
    Client->>Constructor: new ProjectileStreamUpdate()
    Constructor->>Member: std::fill(m_projectileIDs, ..., INVALID_ID)
    Constructor->>Member: m_nextFreeIndex = 0
    Constructor->>Member: m_firstValidIndex = 0
    Constructor->>Member: m_owningObject = INVALID_ID
    Constructor-->>Client: Return (properly initialized)
Loading

Copy link

@Mauller Mauller left a comment

Choose a reason for hiding this comment

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

Looks good, just needs replicating

@xezon xezon changed the title fix: Fix ProjectileStreamUpdate's constructor and initialize m_projectileIDs fix(update): Fix value initialization of ProjectileStreamUpdate::m_projectileIDs Feb 3, 2026
@xezon xezon merged commit 4b79ebf into TheSuperHackers:main Feb 3, 2026
26 checks passed
@Caball009 Caball009 deleted the fix_constructor_ProjectileStreamUpdate branch February 3, 2026 20:08
githubawn pushed a commit to githubawn/GeneralsGameCode that referenced this pull request Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Minor 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.

3 participants