Repository navigation
Handhelds: the later levels fit (only used textures, level freed before the next cutscene, smaller renderer and task state) - #3
Merged
Conversation
…re the next cutscene, smaller renderer and task state) On the ESP32-S3-BOX, JABSHIP (mission 10) could not be loaded at all (out of memory loading KELL.WAX), and finishing NARSHADA crashed in the next mission's cutscene. With TFE_ESPBOX: - Only the textures the sectors and walls use are loaded, once they are read (level_loadUsedTextures()): a level's list can name many it never draws (JABSHIP lists 359 and draws 51: 1.1MB). The other slots stay null like <NoTexture>; INF only copies textures from one sector or wall to another, and old save states (which list every texture) still load. - At mission end the level is freed before the next mode starts, not after: the next mission's cutscene (jabba1: ~1MB) no longer has to fit next to the level that just ended (NARSHADA: 1.7MB). - adjoinEdgeList has MAX_ADJOIN_SEG entries: wall_addAdjoinSegment() keeps the index below that for the whole frame (-253KB of renderer state). - Task stacks are 2KB: they hold the local contexts of up to 16 nested task functions, none over 64 bytes (-96KB per chunk of 16 tasks; ctxAllocate() still asserts that they fit). - Loading a save state frees the loaders' read buffers too, as a level load does (espbox_free_loader_scratch()). On the box, with the code overlay (PSRAM free): - Talay 1275 KB -> 1778 KB, render time unchanged (13.0 ms) - NARSHADA 1080 KB -> 1431 KB; finishing it with LASKIP plays jabba1 and loads JABSHIP (1329 KB free), where it crashed before - JABSHIP directly (warp from Talay, or from the agent menu): crashed -> 1762 KB free, 51 of 359 textures loaded - ARC (mission 14) 937 KB free; a save made in ARC loads back in ARC (795 KB free) and from the title (925 KB) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
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.
Summary
On the ESP32-S3-BOX, JABSHIP (mission 10) couldn't be loaded at all: loading KELL.WAX ran out of memory. Finishing NARSHADA crashed in the next mission's cutscene. All changes are under
TFE_ESPBOX:level_loadUsedTextures()). Loading happens once the sectors and walls are read.<NoTexture>.adjoinEdgeListhasMAX_ADJOIN_SEGentries.wall_addAdjoinSegment()keeps the index below that for the whole frame. That's −253 KB of renderer state.ctxAllocate()still asserts that they fit.espbox_free_loader_scratch()), as a level load does.Testing on the box
This was tested with the code overlay (esp-cpp/esp-box-emu#145). A temporary test hook, not committed, typed cheats into the game.
Before and after, PSRAM free:
LASKIP)The whole campaign goes from the Talay save,
LASECBASE, thenLASKIPmission after mission, through the ending cutscenes and the credits. Each line is free PSRAM in the level (largest free block):There was no crash and no failed allocation in the whole run.
¹ In JABSHIP no typed cheat had any effect (
LASKIP,LAPOSTAL), while they worked in the nine levels before it. So the chain continued with a warp to IMPCITY, and the JABSHIP → IMPCITY transition is the one that wasn't exercised. This only affects the test hook's typed cheats, which the handhelds can't reach otherwise. I haven't found the cause.Review
A separate read-only review traced every user of level texture slots: INF stops and triggers, animated textures, serialization in all three old/new directions. It also traced every
startNextMode()branch after the earlier free, the adjoin index bound, and the worst-case task context size. It found no defects.🤖 Generated with Claude Code
https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY