Skip to content

ESP32: keys work at the menus after JK is quit and relaunched; console commands too - #4

Merged
finger563 merged 1 commit into
esp32p4from
esp32/second-session-keys
Nov 23, 2026
Merged

finger563 merged 1 commit into
esp32p4from
esp32/second-session-keys

Conversation

@finger563

@finger563 finger563 commented Nov 23, 2026 •

Copy link
Copy Markdown

After JK was quit and relaunched, keys stopped working at the menus

tab5-emu runs the engine several times in one process. Desktop resets every global at each launch (OpenJKDF2_Globals_Reset in main.c), but that doesn't run on ESP32, so state that assumes a fresh process carried over to the next session:

  • The message handler table.
    • jk_esp_engine_startup reset g_handler_count but not Window_ext_handlers[].
    • stdControl_MessageHandler is never removed, and on ESP32 neither is Windows_GdiHandler (Windows_ShutdownGdi is gated on a flag only the Win32 path sets). So their re-adds in session 2 were refused as duplicates and the count came out 2 short.
    • Dispatch visits only g_handler_count slots, so it stopped before jkGuiRend_WindowHandler. In the second session keys and taps were ignored at every menu: the first tally waited forever for Enter, and Esc no longer opened the in-game menu.
    • Only the on-screen pad kept working, because jkGuiRend_UpdateController calls the GUI's handler directly.
    • Logged on the device at the tally: session 1 had count 4 with the GUI's handler in slot 3; session 2 had count 2 with the same four entries.
    • Fix: Window_ESP32_ResetMsgHandlers() clears the table and the count at session start.
  • sithConsole_numRegisteredCmds and jkDev_numCheats outlived their tables. Each session registered on top of the previous one's count, and from the third session every console command and cheat was refused ("Console command thereisnotry not recognized"). Both are now reset when their tables are made.

Testing (Tab5, with esp-cpp/tab5-emu#39)

Four JK sessions in one boot. Each one starts level 1, ends it for real (cutscene, tally, Enter) and reaches level 2, then quits.

Before Now
Session 2: tally after level 1 ignores Enter forever advances (handler count 4 in every session)
Session 3: console commands and cheats "not recognized" work
Sessions 1–4 all reach level 2; launcher at 18,833 K after each quit

The same freeze happened on a build without #3, so it was already there. That PR's runs never relaunched JK in the same boot.

Reviewed adversarially. An audit of every state that survives a session in the window, GUI and input paths found the same cause independently. A review of this patch found no defects; its one finding was an existing out-of-memory path that both skeptics rejected. The broader fix, running OpenJKDF2_Globals_Reset per session on ESP32, would also reset globals the port sets up before engine startup, so it is left for a separate audit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY

…e commands too

tab5-emu runs the engine several times in one process, and desktop's
per-launch OpenJKDF2_Globals_Reset doesn't run there, so state that assumes a
fresh process carried over:

- The message handler table. jk_esp_engine_startup reset only the count.
  stdControl's handler is never removed, and on ESP32 neither is
  Windows_GdiHandler, so their re-adds were refused as duplicates. Dispatch
  visits g_handler_count slots and stopped before the GUI's handler: in the
  second session keys and taps were ignored at every menu (the first tally
  waited forever for Enter) and Esc no longer opened the in-game menu. Only
  the on-screen pad still worked, because jkGuiRend_UpdateController calls
  the GUI's handler directly. Window_ESP32_ResetMsgHandlers clears the table
  and the count at session start.
- sithConsole_numRegisteredCmds and jkDev_numCheats outlived their tables.
  Each session registered on top of the last one's count, and from the third
  session every console command and cheat was refused ("not recognized").
  Both are reset when their tables are made.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
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