From 9509e07934fcbe24d83191dbcedc08de489c08b4 Mon Sep 17 00:00:00 2001 From: RedBlackAka <140876408+RedBlackAka@users.noreply.github.com> Date: Mon, 15 Dec 2025 18:36:00 +0100 Subject: [PATCH] Handle more things for end emulation --- src/gui/wxgui/MainWindow.cpp | 50 +++++++++++++++++++------- src/gui/wxgui/MainWindow.h | 1 + src/gui/wxgui/input/HotkeySettings.cpp | 11 ++++++ src/gui/wxgui/wxCemuConfig.cpp | 3 ++ src/gui/wxgui/wxCemuConfig.h | 3 ++ 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/gui/wxgui/MainWindow.cpp b/src/gui/wxgui/MainWindow.cpp index 549f7c1a..dad5ea85 100644 --- a/src/gui/wxgui/MainWindow.cpp +++ b/src/gui/wxgui/MainWindow.cpp @@ -601,12 +601,7 @@ bool MainWindow::FileLoad(const fs::path launchPath, wxLaunchGameEvent::INITIATE #endif if (GetConfig().disable_screensaver) - { ScreenSaver::SetInhibit(true); - // TODO: disable when only the game, not Cemu, is closed (a feature not yet implemented) - // currently unnecessary because this will happen automatically when Cemu closes - // ScreenSaver::SetInhibit(false); - } if (FullscreenEnabled()) SetFullScreen(true); @@ -686,13 +681,7 @@ void MainWindow::OnFileMenu(wxCommandEvent& event) } else if (menuId == MAINFRAME_MENU_ID_FILE_END_EMULATION) { - CafeSystem::ShutdownTitle(); - DestroyCanvas(); - m_game_launched = false; - RecreateMenu(); - CreateGameListAndStatusBar(); - DoLayout(); - UpdateChildWindowTitleRunningState(); + EndEmulation(); } } @@ -1771,6 +1760,42 @@ void MainWindow::SetFullScreen(bool state) SetMenuVisible(true); } +void MainWindow::EndEmulation() // unfinished - memory leaks and crashes after repeated use (after 3x usually) +{ + CafeSystem::ShutdownTitle(); + DestroyCanvas(); + m_game_launched = false; + m_launched_game_name.clear(); + #ifdef ENABLE_DISCORD_RPC + if (m_discord) + m_discord->UpdatePresence(DiscordPresence::Idling, ""); + #endif + + if (GetConfig().disable_screensaver) + ScreenSaver::SetInhibit(false); + + // close memory searcher if created + if (m_toolWindow) + { + m_toolWindow->Close(); + m_toolWindow = nullptr; + m_memorySearcherMenuItem->Enable(false); + } + + // unsure about this, but seems to free up additional 10 MB memory, see LatteThread.cpp + if (g_renderer) + { + g_renderer->Shutdown(); + delete g_renderer.get(); + g_renderer.release(); + } + + RecreateMenu(); + CreateGameListAndStatusBar(); + DoLayout(); + UpdateChildWindowTitleRunningState(); +} + void MainWindow::SetMenuVisible(bool state) { if (m_menu_visible == state) @@ -2167,6 +2192,7 @@ void MainWindow::RecreateMenu() // add 'Stop emulation' menu entry to file menu #ifdef CEMU_DEBUG_ASSERT m_fileMenu->Append(MAINFRAME_MENU_ID_FILE_END_EMULATION, _("Stop emulation")); + m_fileMenuSeparator1 = m_fileMenu->AppendSeparator() #endif } diff --git a/src/gui/wxgui/MainWindow.h b/src/gui/wxgui/MainWindow.h index 0e80b16d..eec043b8 100644 --- a/src/gui/wxgui/MainWindow.h +++ b/src/gui/wxgui/MainWindow.h @@ -71,6 +71,7 @@ public: [[nodiscard]] bool IsGameLaunched() const { return m_game_launched; } void SetFullScreen(bool state); + void EndEmulation(); void SetMenuVisible(bool state); void UpdateNFCMenu(); bool IsMenuHidden() const; diff --git a/src/gui/wxgui/input/HotkeySettings.cpp b/src/gui/wxgui/input/HotkeySettings.cpp index 0bf59025..cadf3e9d 100644 --- a/src/gui/wxgui/input/HotkeySettings.cpp +++ b/src/gui/wxgui/input/HotkeySettings.cpp @@ -6,6 +6,7 @@ #include "HotkeySettings.h" #include "MainWindow.h" +#include #include #if BOOST_OS_WINDOWS @@ -157,6 +158,9 @@ HotkeySettings::HotkeySettings(wxWindow* parent) CreateHotkeyRow(_tr("Toggle fullscreen"), s_cfgHotkeys.toggleFullscreen); CreateHotkeyRow(_tr("Take screenshot"), s_cfgHotkeys.takeScreenshot); CreateHotkeyRow(_tr("Toggle fast-forward"), s_cfgHotkeys.toggleFastForward); +#ifdef CEMU_DEBUG_ASSERT + CreateHotkeyRow(_tr("End emulation"), s_cfgHotkeys.endEmulation); +#endif m_controllerTimer = new wxTimer(this); Bind(wxEVT_TIMER, &HotkeySettings::OnControllerTimer, this); @@ -192,6 +196,13 @@ void HotkeySettings::Init(MainWindow* mainWindowFrame) {&s_cfgHotkeys.toggleFastForward, [](void) { ActiveSettings::SetTimerShiftFactor((ActiveSettings::GetTimerShiftFactor() < 3) ? 3 : 1); }}, +#ifdef CEMU_DEBUG_ASSERT + {&s_cfgHotkeys.endEmulation, [](void) { + wxTheApp->CallAfter([]() { + s_mainWindow->EndEmulation(); + }); + }}, +#endif }); s_keyboardHotkeyToFuncMap.reserve(s_cfgHotkeyToFuncMap.size()); diff --git a/src/gui/wxgui/wxCemuConfig.cpp b/src/gui/wxgui/wxCemuConfig.cpp index bbd24ab4..3c5080d2 100644 --- a/src/gui/wxgui/wxCemuConfig.cpp +++ b/src/gui/wxgui/wxCemuConfig.cpp @@ -115,6 +115,9 @@ void wxCemuConfig::Load(XMLConfigParser& parser) hotkeys.toggleFullscreenAlt = xml_hotkeys.get("ToggleFullscreenAlt", sHotkeyCfg{uKeyboardHotkey{WXK_CONTROL_M, true}}); // ALT+ENTER hotkeys.takeScreenshot = xml_hotkeys.get("TakeScreenshot", sHotkeyCfg{uKeyboardHotkey{WXK_F12}}); hotkeys.toggleFastForward = xml_hotkeys.get("ToggleFastForward", sHotkeyCfg{}); +#ifdef CEMU_DEBUG_ASSERT + hotkeys.endEmulation = xml_hotkeys.get("EndEmulation", sHotkeyCfg{uKeyboardHotkey{WXK_F5}}); +#endif } void wxCemuConfig::Save(XMLConfigParser& config) diff --git a/src/gui/wxgui/wxCemuConfig.h b/src/gui/wxgui/wxCemuConfig.h index 9463d4df..a2f758dd 100644 --- a/src/gui/wxgui/wxCemuConfig.h +++ b/src/gui/wxgui/wxCemuConfig.h @@ -127,6 +127,9 @@ struct wxCemuConfig sHotkeyCfg exitFullscreen; sHotkeyCfg takeScreenshot; sHotkeyCfg toggleFastForward; +#ifdef CEMU_DEBUG_ASSERT + sHotkeyCfg endEmulation; +#endif } hotkeys{}; void AddRecentlyLaunchedFile(std::string_view file);