Renderer: fix texture lookup paths + skip garbage Tile slots (r3) - #3
Merged
Merged
Conversation
Two issues showed up running r2 on real Mavericks hardware (issue #2): 1. Every PNG was rendering as a flat random-coloured rectangle. The iOS-style loadTexture() was stripping both the directory and the extension before passing the name to NSBundle's pathForResource:, but our app bundle keeps the data/ layout from the engine repo (Contents/Resources/images/gui/gui.png, font/default8.png, etc.). pathForResource: only finds top-level Resources/ + *.lproj, so every call failed and the renderer fell back to its noise texture. Keep the subdirectory now and try a few likely Resources-relative directories with pathForResource:ofType:inDirectory:. 2. Loading any newly-created world crashed with SIGSEGV in Chunk::rebuild() inside the renderer thread. Disassembly showed the crash at 'mov rax, [rbx]' where rbx came straight out of Tile::tiles[tileId] — the slot wasn't NULL, it held an obvious page-zero garbage pointer (0x1d10). Boot diagnostics already warn about a few stale slots ('Missing category for tile 95/255'), so just guard Chunk::rebuild() against tile IDs that map to NULL or to a sub-0x10000 pointer instead of letting the vtable load fault. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the two issues #2 reported running r2 on real Mavericks hardware.
1. All PNG textures rendered as flat coloured rectangles
loadTexture("gui/gui.png")was stripping both the directory and the extension before handing the result to[NSBundle pathForResource:ofType:]. Two problems with that:pathForResource:ofType:only looks in top-levelResources/(and*.lprojchildren), but our bundle keeps thehandheld/data/layout, so the real files are atResources/images/gui/gui.png,Resources/images/font/default8.png,Resources/images/terrain.png, etc.gui/gui.pngandgui/gui2.png) would also collide on the same lookup key.Every texture call therefore fell to the
LOGI("Couldn't find file:")branch and the renderer used its random-noise fallback — which is exactly the "buttons are coloured rectangles, no text" symptom the user reported.Fix: keep the subdirectory and search a few likely Resources-relative directories with
pathForResource:ofType:inDirectory:, falling back to the flat lookup for any iOS-style bundles, then to the dev-timedata/images/layout.2. SIGSEGV in
Chunk::rebuild()after loading any worldCrash log from #2 shows:
Disassembly of
Chunk::rebuild + 640lands onmov rax, qword ptr [rbx]whererbxis the value ofTile::tiles[tileId]. The slot isn't NULL — it's page-zero garbage (0x1d10). Boot diagnostics already warn that a few slots are inconsistent (Error: Missing category for tile 95/255), so the renderer now guards against both NULL and obviously-bogus sub-0x10000pointers before dereferencing the vtable.Test
-arch x86_64 -mmacosx-version-min=10.9 -stdlib=libstdc++.NOUNDEFS | DYLDLINK | TWOLEVEL | WEAK_DEFINES | BINDS_TO_WEAK | PIE), 3.1 MB release.Contents/Resources/images/gui/gui.png, etc.).