diff --git a/src/Gui/jkGUITitle.c b/src/Gui/jkGUITitle.c index bd2cbb7f2..171a80376 100644 --- a/src/Gui/jkGUITitle.c +++ b/src/Gui/jkGUITitle.c @@ -105,6 +105,13 @@ void jkGuiTitle_Shutdown() // Added: clean reset memset(jkGuiTitle_versionBuffer, 0, sizeof(jkGuiTitle_versionBuffer)); jkGuiTitle_loadPercent = 0; + for (int i = 0; i < 20; i++) // Added: the last level's loading-screen texts + { + if (jkGuiTitle_aTexts[i].str) { + STD_FREE(jkGuiTitle_aTexts[i].str); + jkGuiTitle_aTexts[i].str = NULL; + } + } } char jkGuiTitle_sub_4189A0(char *a1) @@ -145,9 +152,9 @@ char16_t* jkGuiTitle_quicksave_related_func1(stdStrTable *strTable, char *jkl_fn // Added: cleanup for (int i = 0; i < 20; i++) { - if (texts->str) { - STD_FREE(texts->str); - texts->str = NULL; + if (jkGuiTitle_aTexts[i].str) { // Added: each text (was texts[0] twenty times) + STD_FREE(jkGuiTitle_aTexts[i].str); + jkGuiTitle_aTexts[i].str = NULL; } } _memset(jkGuiTitle_aTexts, 0, sizeof(jkGuiTitle_aTexts)); diff --git a/src/Main/jkHudInv.c b/src/Main/jkHudInv.c index b3a014be3..095524ac2 100644 --- a/src/Main/jkHudInv.c +++ b/src/Main/jkHudInv.c @@ -1007,7 +1007,7 @@ int jkHudInv_Shutdown() jkHudInv_aBitmaps[2] = 0; } - for (int i = 0; i < 100; i++) + for (int i = 0; i < SITHBIN_NUMBINS; i++) // Added: all the bins jkHudInv_LoadItemRes loads (was 100) { if ( (sithInventory_g_aTypes[i].flags & 0xA) != 0 && sithInventory_g_aTypes[i].hudBitmap ) { diff --git a/src/Platform/ESP32/Window_ESP32.c b/src/Platform/ESP32/Window_ESP32.c index d58e5ded5..ed0942d98 100644 --- a/src/Platform/ESP32/Window_ESP32.c +++ b/src/Platform/ESP32/Window_ESP32.c @@ -95,17 +95,16 @@ void Window_Main_Loop() int jk_esp_engine_startup(const char* game_dir) { + // Every engine global back to its boot value, as desktop's main.c does + // before each launch: tab5-emu runs the engine more than once per process. + // The session arrays (jk_esp_arrays_alloc, already made) keep their pointers + // and only have their contents zeroed (PLATFORM_SESSION_ARRAYS). + OpenJKDF2_Globals_Reset(); + char cmdLine[256]; strncpy(cmdLine, jk_esp_engine_args(), sizeof(cmdLine) - 1); cmdLine[sizeof(cmdLine) - 1] = 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; - g_hInstance = 0; - g_nShowCmd = 0; - // the engine opens everything relative to the working directory if (game_dir && game_dir[0]) { chdir(game_dir); diff --git a/src/Win95/Window.c b/src/Win95/Window.c index 41cb86c3f..ee015955b 100644 --- a/src/Win95/Window.c +++ b/src/Win95/Window.c @@ -151,25 +151,6 @@ 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 ce62bf9c1..cd2fec387 100644 --- a/src/Win95/Window.h +++ b/src/Win95/Window.h @@ -23,9 +23,6 @@ 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);