From 79cd8d219010c7b5bbe74ba8a2c8e29c8e3d96ad Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Thu, 10 Sep 2020 18:05:54 -0400 Subject: [PATCH] GUI: Fix recording related hang when PAD plugin is open/closed while game is paused (#3299) * recording: Resolve hang when opening PAD plugin with the game paused * pcsx2-gui: Forbid editing the PAD settings while emulation is paused by recording tools * pcsx2-gui: Resume emulation before configuring PAD plugin, resume on return --- pcsx2/gui/MainMenuClicks.cpp | 43 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/pcsx2/gui/MainMenuClicks.cpp b/pcsx2/gui/MainMenuClicks.cpp index 0447a8ef58079..a536a3db8a503 100644 --- a/pcsx2/gui/MainMenuClicks.cpp +++ b/pcsx2/gui/MainMenuClicks.cpp @@ -32,9 +32,11 @@ #ifndef DISABLE_RECORDING # include "Recording/InputRecording.h" +# include "Recording/RecordingControls.h" # include "Recording/VirtualPad.h" #endif + using namespace Dialogs; void MainEmuFrame::Menu_SysSettings_Click(wxCommandEvent &event) @@ -471,7 +473,7 @@ void MainEmuFrame::Menu_EnableBackupStates_Click( wxCommandEvent& ) // (1st save after the toggle keeps the old pre-toggle value).. // wonder what that means for all the other menu checkboxes which only use AppSaveSettings... (avih) AppApplySettings(); - + AppSaveSettings(); } @@ -553,7 +555,7 @@ void MainEmuFrame::Menu_EnableRecordingTools_Click(wxCommandEvent&) void MainEmuFrame::Menu_EnableHostFs_Click( wxCommandEvent& ) { g_Conf->EmuOptions.HostFs = GetMenuBar()->IsChecked( MenuId_EnableHostFs ); - AppSaveSettings(); + AppSaveSettings(); } void MainEmuFrame::Menu_OpenELF_Click(wxCommandEvent&) @@ -655,20 +657,47 @@ void MainEmuFrame::Menu_SysShutdown_Click(wxCommandEvent &event) CoreThread.Reset(); } -void MainEmuFrame::Menu_ConfigPlugin_Click(wxCommandEvent &event) +void MainEmuFrame::Menu_ConfigPlugin_Click(wxCommandEvent& event) { const int eventId = event.GetId() - MenuId_PluginBase_Settings; PluginsEnum_t pid = (PluginsEnum_t)(eventId / PluginMenuId_Interval); // Don't try to call the Patches config dialog until we write one. - if (event.GetId() == MenuId_Config_Patches) return; + if (event.GetId() == MenuId_Config_Patches) + return; - if( !pxAssertDev( (eventId >= 0) || (pid < PluginId_Count), "Invalid plugin identifier passed to ConfigPlugin event handler." ) ) return; + if (!pxAssertDev((eventId >= 0) || (pid < PluginId_Count), "Invalid plugin identifier passed to ConfigPlugin event handler.")) + return; wxWindowDisabler disabler; - ScopedCoreThreadPause paused_core( new SysExecEvent_SaveSinglePlugin(pid) ); - GetCorePlugins().Configure( pid ); + ScopedCoreThreadPause paused_core(new SysExecEvent_SaveSinglePlugin(pid)); + +#ifndef DISABLE_RECORDING + if (pid == PluginId_PAD) + { + // The recording features involve pausing emulation, and can be resumed ideally via key-bindings. + // + // However, since the PAD plugin is used to do so, if it's closed then there is nothing to read + // the keybind resulting producing an unrecovable state. + // + // If the CoreThread is paused prior to opening the PAD plugin settings then when the settings + // are closed the PAD will not re-open. To avoid this, we resume emulation prior to the plugins + // configuration handler doing so. + if (g_Conf->EmuOptions.EnableRecordingTools && g_RecordingControls.IsEmulationAndRecordingPaused()) + { + g_RecordingControls.Unpause(); + GetCorePlugins().Configure(pid); + g_RecordingControls.Pause(); + } + else + GetCorePlugins().Configure(pid); + } + else + GetCorePlugins().Configure(pid); +#else + GetCorePlugins().Configure(pid); +#endif } void MainEmuFrame::Menu_Debug_Open_Click(wxCommandEvent &event)