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
{{ message }}
Repository navigation
bugfix(w3dtreebuffer): Fix crash when no tree model can be found - #3695
A tree whose model cannot be found falls back to tree type 0, the first tree type that loads. If no tree model loads at all, tree type 0 has no data, and unitMoved() and saving the game crashed on it. Now both skip trees whose tree type is not loaded.
Players report frequent crashes right after start, on the shell map behind the main menu. Their installations fail to load the tree models.
Quick reproduction: in the Zero Hour folder, create empty files Art/W3D/<model>.w3d for all tree models of the shell map: PTCypress01, PTDogwod01, PTDogwod02, PTDogwod03, PTMaple01, PTXBirch01, PTXFIR02, PTXMaple02, PTXPine03 (one loaded tree type is enough to hide the bug). Start the game: it crashes on the main menu within seconds. With the fix, the game keeps running without these trees, and a skirmish game can be saved and loaded.
No actionable comments were generated in the recent review.
Walkthrough
unitMoved skips partition entries with deleted or out-of-range tree types. xfer reads model and texture names only when the tree type is not deleted and is within the current type range.
Changes
Tree Type Bounds
Layer / File(s)
Summary
Guard tree type access Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp
unitMoved skips deleted or out-of-range partition entries. xfer reads model and texture names only for non-deleted tree types below m_numTreeTypes.
The change stops the startup crash when tree models are missing and the save-time crash that followed from it. A residual edge case remains: failed tree types are still stored as type 0, so a tree could later be shown with the wrong model if another type loads afterwards. Mergeable, with owner awareness of that follow-up.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the W3DTreeBuffer crash fix, which matches the changeset. The summary shows unitMoved now skips tree types that are not loaded, and the description says the crash occurs when no tree m…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description explains the bug: trees whose model fails to load fall back to tree type 0, which has no data when no tree model loads, so unitMoved() and game saving crash. It names the affected file…
Full details: Title check
Explanation
The title names the W3DTreeBuffer crash fix, which matches the changeset. The summary shows unitMoved now skips tree types that are not loaded, and the description says the crash occurs when no tree model loads. The title is specific and accurate. The 'bugfix(...)' prefix is a conventional commit style, which is acceptable.
Full details: Description check
Explanation
The description explains the bug: trees whose model fails to load fall back to tree type 0, which has no data when no tree model loads, so unitMoved() and game saving crash. It names the affected files' behavior, gives a reproduction, and includes a stack trace through W3DTreeBuffer::unitMoved. This matches the raw summary, which says unitMoved now skips unloaded tree types and xfer serializes only loaded types.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Major · Return a negative value from every failed addTreeType path. · W3DTreeBuffer.cpp:1282
Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp:1282 Major · Stability & Availability · Quick win
Return a negative value from every failed addTreeType path.
When no model loads, addTreeType returns 0 and m_numTreeTypes stays 0. addTree accepts 0 because it only rejects negative values. The tree is stored with type 0. The new unitMoved guard skips it, but save-mode xfer still reads m_treeTypes[0].m_data without a bounds check. That slot is never assigned on this path, so the save can crash.
If another model loads later, it takes index 0. The failed tree then uses that model's data for rendering and movement.
Return -1 on each failure path. addTree then rejects the tree before it is stored. The MAX_TYPES path returns 0 in the same way, so it is included.
Suggested fix
DEBUG_CRASH(("Too many kinds of trees in map. Reduce kinds of trees, or raise tree limit. jba."));
- return 0;+ return -1;
DEBUG_CRASH(("Unable to find model for tree %s", data->m_modelName.str()));
- return 0;+ return -1;
DEBUG_CRASH(("Tree %s is not simple mesh. Tell artist to re-export. Don't Ignore!!!", data->m_modelName.str()));
- return 0;+ return -1;
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 2d586144-b566-415c-a586-d42ade92ecdc
Commits
Reviewing files that changed from the base of the PR and between 45b1b4d and 17cc987.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
Having the game crash when tree models cannot be loaded sound like correct behaviour. If assets cannot be loaded, the game should not continue.
What happens if the tree's are not loaded and somebody plays a multiplayer game? Will it mismatch?
Missing assets between players are what the INI CRC check at match start is for, and it tells the player clearly why the match cannot start. Two players with the same broken or modified assets pass that check and can play the whole match without crashes or mismatches. Many mods ship with asset problems like this, so crashing here does not help anyone.
No mismatch: the tree buffer is client side only, its crc() is empty and the logic never reads it. Tree objects and their geometry come from INI, not from the models.
The save crash is real: reproduced and fixed in 5108ae3. Saving now skips a tree type that is not loaded, as loading already does.
Returning 0 from addTreeType() is EA's original logic, not something this PR adds: a tree with a missing model is drawn with the first tree type that loads. Returning -1 would remove that EA fallback, so this PR keeps it and only adds the checks EA missed.
For best results, initiate chat on the files or code changes.
Analysis chain
Script executed:
#!/bin/bashset -u
file="Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp"printf'%s\n''--- File outline ---'
ast-grep outline "$file" --items all --match 'addTreeType|unitMoved|xfer|crc'printf'%s\n''--- Relevant code locations ---'
rg -n -C 5 'addTreeType\s*\(|unitMoved\s*\(|::xfer\s*\(|::crc\s*\(|m_numTreeTypes|TREE_TYPE_DELETED'"$file"printf'%s\n''--- Commit summary and patch ---'
git show --format=fuller --stat 5108ae319 --
git show --format= --no-ext-diff 5108ae319 -- "$file"
Length of output: 9683
Script executed:
#!/bin/bashset -u
file="Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp"printf'%s\n''--- addTreeType and addTree ---'
cat -n "$file"| sed -n '1260,1385p'printf'%s\n''--- xfer ---'
cat -n "$file"| sed -n '1854,1975p'printf'%s\n''--- treeType consumers ---'
rg -n -C 2 'm_trees\[[^]]+\]\.treeType|tree\.treeType'"$file"printf'%s\n''--- pull request base and head ---'
gh pr view 3695 --repo TheSuperHackers/GeneralsGameCode --json baseRefOid,headRefOid --jq '"base=\(.baseRefOid) head=\(.headRefOid)"'
Length of output: 15559
@Okladnoj Thanks for reproducing the save crash and explaining the fallback.
I checked commit 5108ae319. Saving now writes empty model and texture names for an unloaded type. Loading skips the tree when it finds no matching type.
I agree that returning -1 from addTreeType() would remove the existing type-0 fallback, rather than just guard the crash. I did not run the game or repeat the save test.
📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.
If you found this review helpful, would you consider giving us a shout-out on X?
The reason will be displayed to describe this comment to others. Learn more.
Missing assets between players are what the INI CRC check at match start is for,
I'm pretty sure Zero Hour does not do an INI CRC check at match start - it was disabled by EA. Only Generals does.
Which means your fix will cause a mismatch if one player has missing assets - which it shouldn't have in the first place unless assets were modified. And that brings me back to my original point: This is a data issue/corruption which should not allow the game to be started.
I'm pretty sure Zero Hour does not do an INI CRC check at match start - it was disabled by EA. Only Generals does.
Which means your fix will cause a mismatch if one player has missing assets - which it shouldn't have in the first place unless assets were modified. And that brings me back to my original point: This is a data issue/corruption which should not allow the game to be started.
Tree models aren't part of the INI CRC anywhere: not in Generals, not in Zero Hour, and not in GeneralsOnline, which is set to merge with Zero Hour. The game has no mechanism that keeps a player with broken models out. All it has is this crash, often right in the main menu.
And the fix can't cause a mismatch. Logic only notifies the client that a unit moved (Object.cpp); from there W3DTreeBuffer just animates toppling and pushing aside, with its FX on the client random. Nothing goes back to logic, and the buffer's crc() is empty.
Once they merge, most players will play online, where pre-match checks are already in place, the INI CRC check among them. There is even less reason to crash the game over a missing tree model there.
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
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.
A tree whose model cannot be found falls back to tree type 0, the first tree type that loads. If no tree model loads at all, tree type 0 has no data, and
unitMoved()and saving the game crashed on it. Now both skip trees whose tree type is not loaded.Players report frequent crashes right after start, on the shell map behind the main menu. Their installations fail to load the tree models.
Quick reproduction: in the Zero Hour folder, create empty files
Art/W3D/<model>.w3dfor all tree models of the shell map:PTCypress01,PTDogwod01,PTDogwod02,PTDogwod03,PTMaple01,PTXBirch01,PTXFIR02,PTXMaple02,PTXPine03(one loaded tree type is enough to hide the bug). Start the game: it crashes on the main menu within seconds. With the fix, the game keeps running without these trees, and a skirmish game can be saved and loaded.Stack trace (macOS, arm64)