Handle more things for end emulation

This commit is contained in:
RedBlackAka 2025-12-15 18:36:00 +01:00 committed by RedBlackAka
parent 0ddcba4ff1
commit 9509e07934
5 changed files with 56 additions and 12 deletions

View File

@ -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
}

View File

@ -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;

View File

@ -6,6 +6,7 @@
#include "HotkeySettings.h"
#include "MainWindow.h"
#include <wx/app.h>
#include <wx/clipbrd.h>
#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());

View File

@ -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)

View File

@ -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);