Skip to content

bugfix(w3dtreebuffer): Fix crash when no tree model can be found - #3695

Open
Okladnoj wants to merge 2 commits into
TheSuperHackers:mainfrom
Okladnoj:okji/fix/tree-type-missing-model
Open

Okladnoj wants to merge 2 commits into
TheSuperHackers:mainfrom
Okladnoj:okji/fix/tree-type-missing-model

Conversation

@Okladnoj

@Okladnoj Okladnoj commented Nov 16, 2026 •

Copy link
Copy Markdown

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.

Stack trace (macOS, arm64)
FATAL: Caught signal 11
CRASH FAULT ADDRESS: 0x20 code 2
CRASH REGISTERS: pc 0x102a08d80 lr 0x102a08d5c sp 0x16d9b4580 fp 0x16d9b46a0 x0 0x0 x19 0x0 x20 0x50 x21 0x78ddcf8a58
CRASH FAULT REGION: unmapped, next region 0x102448000
CRASH BACKTRACE:
0   GeneralsOnlineZH                    0x0000000102451670 _ZL18macosSignalHandleriP9__siginfoPv + 1176
1   libsystem_platform.dylib            0x00000001a140a144 _sigtramp + 56
2   GeneralsOnlineZH                    0x0000000102a08d5c _ZN13W3DTreeBuffer9unitMovedEP6Object + 1072
3   GeneralsOnlineZH                    0x000000010269118c _ZN6Object38setTriggerAreaFlagsForChangeInPositionEv + 180
4   GeneralsOnlineZH                    0x0000000102691038 _ZN6Object22reactToTransformChangeEPK8Matrix3DPK7Coord3Df + 300
5   GeneralsOnlineZH                    0x000000010250f024 _ZN5Thing11setPositionEPK7Coord3D + 152
6   GeneralsOnlineZH                    0x0000000102672280 _ZN11OpenContain17redeployOccupantsEv + 72
7   GeneralsOnlineZH                    0x000000010269102c _ZN6Object22reactToTransformChangeEPK8Matrix3DPK7Coord3Df + 288
8   GeneralsOnlineZH                    0x000000010250ef78 _ZN5Thing18setTransformMatrixEPK8Matrix3D + 144
9   GeneralsOnlineZH                    0x000000010270a264 _ZN15PhysicsBehavior6updateEv + 1592
10  GeneralsOnlineZH                    0x00000001027abc64 _ZN9GameLogic6updateEv + 988
11  GeneralsOnlineZH                    0x000000010248ebfc _ZN10GameEngine6updateEv + 588
12  GeneralsOnlineZH                    0x00000001024667ac _ZN15MacOSGameEngine6updateEv + 48
13  GeneralsOnlineZH                    0x000000010248ecb4 _ZN10GameEngine7executeEv + 48
14  GeneralsOnlineZH                    0x0000000102491bac _Z8GameMainv + 200
15  GeneralsOnlineZH                    0x000000010244f6d0 -[GeneralsAppDelegate runGame] + 520
16  libdispatch.dylib                   0x00000001a13c0a34 _dispatch_call_block_and_release + 32
17  libdispatch.dylib                   0x00000001a13da5a0 _dispatch_client_callout + 16
18  libdispatch.dylib                   0x00000001a13f89cc _dispatch_main_queue_drain.cold.6 + 832
19  libdispatch.dylib                   0x00000001a13cfb0c _dispatch_main_queue_drain + 176
20  libdispatch.dylib                   0x00000001a13cfa4c _dispatch_main_queue_callback_4CF + 44
21  CoreFoundation                      0x00000001a06429a8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
22  CoreFoundation                      0x00000001a0604638 __CFRunLoopRun + 1980
23  CoreFoundation                      0x00000001a06dec10 _CFRunLoopRunSpecificWithOptions + 536
24  HIToolbox                           0x00000001aadbc5e0 RunCurrentEventLoopInMode + 320
25  HIToolbox                           0x00000001aadbf96c ReceiveNextEventCommon + 492
26  HIToolbox                           0x00000001aaf45db8 _BlockUntilNextEventMatchingListInMode + 48
27  AppKit                              0x00000001a65f08c0 _DPSBlockUntilNextEventMatchingListInMode + 292
28  AppKit                              0x00000001a62af59c _DPSNextEvent + 576
29  AppKit                              0x00000001a6a465f8 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 832
30  AppKit                              0x00000001a6a460e8 -[NSApplication(NSEventRouting) nextEventMatchingMask:untilDate:inMode:dequeue:] + 344
31  AppKit                              0x00000001a62a2920 -[NSApplication run] + 396
32  GeneralsOnlineZH                    0x000000010244fef0 main + 164
33  dyld                                0x000000019c36cd7c start + 6652

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Change: Bug fix

Suggested labels: Crash, Bug

Suggested reviewers: bobtista, xezon

Merge Risk: Low · up to 5108a

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed 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.

Share

Recent 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: d45c1300-d40e-4864-93a8-8be5aa35116c
Commits

Reviewing files that changed from the base of the PR and between 17cc987 and 5108ae3.

Files selected for processing: 1

  • Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Prevents crashes when no tree model loads.

  • Moving units skip trees whose models did not load.
  • Tree saves skip names for models that did not load.

Reviews (2) · Last reviewed commit: "bugfix(w3dtreebuffer): Fix crash when sa..." · Reviewed by Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Files selected for processing: 1

  • Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@Skyaero42

Copy link
Copy Markdown

Players report frequent crashes right after start, on the shell map behind the main menu. Their installations fail to load the tree models.

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?

@Okladnoj

Okladnoj commented Nov 17, 2026 •

Copy link
Copy Markdown
Author

Hi @Skyaero42

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.

@Okladnoj

Okladnoj commented Nov 17, 2026 •

Copy link
Copy Markdown
Author

@coderabbitai

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.

@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -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/bash
set -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?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@Skyaero42 Skyaero42 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

@Okladnoj

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants