Skip to content

Jedi Knight: the whole campaign runs in one session; no PSRAM lost after quitting at a tally or cutscene - #38

Merged
finger563 merged 1 commit into
mainfrom
fix/jk-cutscene-check-leak
Nov 23, 2026
Merged

finger563 merged 1 commit into
mainfrom
fix/jk-cutscene-check-leak

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Engine side: esp-cpp/OpenJKDF2#3. This PR bumps components/jk/OpenJKDF2 to that branch (58a8df48).

Summary

  • Jedi Knight's campaign can now be played start to finish in one session.
    • Before, 09FuelStation failed to load after levels 1–8 ("Parse problem", largest free block 2 MB).
    • Now all 21 levels and both endings, light and dark, run without a quit.
  • Quitting JK at a tally, a cutscene, a level load or the credits no longer loses 7–10 MB of PSRAM until reboot.
  • Cause: before each cutscene the engine checks that the video file exists.
    • On the way, an OpenJKDF2 QOL path read the whole loose resource/video/X.smk into a plain malloc.
    • The directory walk then replaced that handle with a direct open of the same file, so the copy was never freed: 7.1 MB for 23A.SMK after level 8, 3.3 MB for 25A after level 9.
    • JK's allocator doesn't track that memory, so the leak survived the engine's shutdown.
    • Found with a heap hook that logs the call stack of each allocation of 1 MB or more. Details in the engine PR.

Testing (Tab5)

Both runs: one engine session from a fresh boot. The test harness ends each level for real (thereisnotry: tally, Force screen, cutscene, next level). God mode on, audio muted.

Before Now
Continuous run from level 1 09FuelStation fails to load 01 → 21ajerec and the light ending; 01 → 21bjerec and the dark ending
Largest free PSRAM block at a level's load end 3.9 MB (light, from a fresh level 9); 1.0–2.0 MB (dark, from a fresh 15maw) 9.2 MB at every level from 02 on (8.1 MB at 09)
PSRAM free at 16bEscapeShip / 19A load end (dark) 1.44 MB / 1.3 MB 11.3 MB / 10.5 MB
Launcher PSRAM after quitting at the credits 9.1–11.7 MB 18.8 MB, as after boot
Launcher PSRAM after quitting during a level load 7–10 MB lost 18.8 MB

Cutscenes still play. The fix was reviewed adversarially before testing, and no defects were found.

Found while testing, not caused by this PR: in a second JK session within one boot (any quit and relaunch), the first tally screen ignores Enter, while touch still works. The same happens without this PR. This is probably the "tally unresponsive" seen earlier. Not fixed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY

…o file

esp-cpp/OpenJKDF2 esp32/cutscene-check-leak (58a8df48). Before each
cutscene the engine checked the video file through a path that read the
whole file into memory and never freed it: 7.1 MB for 23A.SMK after level 8,
3.3 MB for 25A after level 9. The rest of the boot lost it too, since the
copy was plain malloc. That is why 09FuelStation failed to load in a
continuous run (largest block 2 MB) and why quitting JK at a tally, a
cutscene or a level load lost 7-10 MB of PSRAM until reboot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
@finger563
finger563 merged commit 3047e79 into main Nov 23, 2026
1 check passed
@finger563
finger563 deleted the fix/jk-cutscene-check-leak branch November 23, 2026 01:31
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.

1 participant