You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fixes a potential game crash if Object::m_drawable is a nullptr when loading a save game.
I'm not sure when this happens normally, but I observed a crash here when testing something. Considering there's a check earlier (at line 3609), it makes sense to have a check here as well.
Caball009
changed the title
fix(object): Avoid crash if Object drawable is nullptr on save game load
fix(object): Avoid crash if Object::m_drawable is a nullptr on save game load
May 14, 2026
This PR adds a null check on draw before calling draw->setID(drawableID) inside Object::xfer(), preventing a crash when m_drawable is nullptr during save-game load. The fix mirrors the existing null-safe ternary already used on the line that retrieves the drawable ID, making the guard consistent.
Added draw && to the XFER_LOAD condition in both Generals/ and GeneralsMD/ copies of Object.cpp, so setID is only called when a drawable actually exists.
Minor cosmetic cleanup: removed redundant blank lines inside the if block and normalized spacing around the condition parentheses.
Confidence Score: 5/5
Safe to merge — the change is a minimal, targeted null guard that prevents a confirmed crash with no functional side effects.
The fix adds a single boolean guard (draw &&) that exactly mirrors the null-safety already present one line above. When draw is null, setID is now skipped rather than dereferenced, which is the only correct behavior since there is no drawable to update. The change is applied symmetrically to both the Generals and Zero Hour copies of the file, keeping them in sync.
Adds null-guard on draw before calling draw->setID() during save-game load to prevent crash when m_drawable is nullptr; also removes redundant blank lines.
Identical null-guard fix applied to the Zero Hour counterpart of the same Object::xfer function.
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Object::xfer(Xfer *xfer)"] --> B["draw = getDrawable()"]
B --> C{"draw != nullptr?"}
C -- Yes --> D["drawableID = draw->getID()"]
C -- No --> E["drawableID = INVALID_DRAWABLE_ID"]
D --> F["xfer->xferDrawableID(&drawableID)"]
E --> F
F --> G{"XFER_LOAD mode?"}
G -- No --> H["skip setID"]
G -- Yes --> I{"draw != nullptr?\n(NEW guard)"}
I -- No --> J["skip setID\n(crash avoided)"]
I -- Yes --> K["draw->setID(drawableID)"]
The reason will be displayed to describe this comment to others. Learn more.
Agree as well
xezon
changed the title
fix(object): Avoid crash if Object::m_drawable is a nullptr on save game load
fix(object): Prevent crash if Object::m_drawable is a nullptr on save load
May 17, 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
CrashThis is a crash, very badGenRelates to GeneralsMinorSeverity: Minor < Major < Critical < BlockerSaveloadIs Saveload/Xfer relatedStabilityConcerns stability of the runtimeZHRelates to Zero Hour
3 participants
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.
This PR fixes a potential game crash if
Object::m_drawableis anullptrwhen loading a save game.I'm not sure when this happens normally, but I observed a crash here when testing something. Considering there's a check earlier (at line 3609), it makes sense to have a check here as well.