diff --git a/src/Devices/sithConsole.c b/src/Devices/sithConsole.c index 566c73cfd..ccfa20b92 100644 --- a/src/Devices/sithConsole.c +++ b/src/Devices/sithConsole.c @@ -23,6 +23,10 @@ int sithConsole_Startup(int maxCmds) { sithConsole_maxCmds = maxCmds; _memset(sithConsole_aCmds, 0, sizeof(stdDebugConsoleCmd) * maxCmds); + // Added: the count outlived the array; a second engine session in one + // process registered on top of the first one's count, and from the + // third on every command (cheats included) was refused as "full" + sithConsole_numRegisteredCmds = 0; DebugGui_fnPrint = 0; DebugGui_fnPrintUniStr = 0; sithCommand_Startup(); diff --git a/src/Main/jkDev.c b/src/Main/jkDev.c index 644c810b9..a5f056a75 100644 --- a/src/Main/jkDev.c +++ b/src/Main/jkDev.c @@ -51,6 +51,7 @@ void jkDev_Startup() jkDev_cheatHashtable = stdHashtbl_New(JKDEV_NUM_CHEATS*2); _memset(jkDev_aCheatCmds, 0, sizeof(stdDebugConsoleCmd) * JKDEV_NUM_CHEATS); + jkDev_numCheats = 0; // Added: like sithConsole's count, it outlived the table sithConsole_RegisterCommand(jkDev_CmdVersion, "version", 0); sithConsole_RegisterCommand(jkDev_CmdTeam, "team", 0); diff --git a/src/Platform/ESP32/Window_ESP32.c b/src/Platform/ESP32/Window_ESP32.c index 71a3e88fb..d58e5ded5 100644 --- a/src/Platform/ESP32/Window_ESP32.c +++ b/src/Platform/ESP32/Window_ESP32.c @@ -99,7 +99,7 @@ int jk_esp_engine_startup(const char* game_dir) strncpy(cmdLine, jk_esp_engine_args(), sizeof(cmdLine) - 1); cmdLine[sizeof(cmdLine) - 1] = 0; - g_handler_count = 0; + Window_ESP32_ResetMsgHandlers(); // the table too, not only the count (see Window.c) g_thing_two_some_dialog_count = 0; g_should_exit = 0; g_window_not_destroyed = 0; diff --git a/src/Win95/Window.c b/src/Win95/Window.c index ee015955b..41cb86c3f 100644 --- a/src/Win95/Window.c +++ b/src/Win95/Window.c @@ -151,6 +151,25 @@ int Window_RemoveMsgHandler(WindowHandler_t a1) return 1; } +#ifdef TARGET_ESP32 +// Added: tab5-emu runs the engine more than once in a process. The handler +// table outlived a session (stdControl's handler is never removed, and +// jkGuiRend_Shutdown forgets the GUI's), but only the count was reset. The next +// session's adds were refused as duplicates, so dispatch, which visits +// g_handler_count slots, stopped before the GUI's handler. Keys and taps were +// ignored at the menus (only the on-screen pad still worked: jkGuiRend_UpdateController +// calls the GUI's handler directly), and Esc no longer opened the in-game menu. +void Window_ESP32_ResetMsgHandlers(void) +{ + for (int i = 0; i < 16; i++) + { + Window_ext_handlers[i].handler = 0; + Window_ext_handlers[i].exists = 0; + } + g_handler_count = 0; +} +#endif + int Window_AddDialogHwnd(HWND a1) { int v1; // eax diff --git a/src/Win95/Window.h b/src/Win95/Window.h index cd2fec387..ce62bf9c1 100644 --- a/src/Win95/Window.h +++ b/src/Win95/Window.h @@ -23,6 +23,9 @@ extern int Window_ySize; int Window_AddMsgHandler(WindowHandler_t a1); int Window_RemoveMsgHandler(WindowHandler_t a1); +#ifdef TARGET_ESP32 +void Window_ESP32_ResetMsgHandlers(void); +#endif int Window_AddDialogHwnd(HWND a1); int Window_msg_main_handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); int Window_Main(HINSTANCE hInstance, int a2, char *lpCmdLine, int nShowCmd, LPCSTR lpWindowName);