From fe9d5a1981cfe43c4535b7473064c9858addb3b5 Mon Sep 17 00:00:00 2001 From: mpnico Date: Sat, 18 Sep 2021 14:31:44 +0200 Subject: [PATCH] Fix problems added by Pause (#2645) * Disable Pause/Resume menu instead of trying to hide them * Fix Resume menu being active before renderer starts * Fix emulator not being able to close properly --- .../Renderer/Server/AudioRenderSystem.cs | 8 ++++++++ .../Renderer/Server/AudioRendererManager.cs | 18 ++++++++++++++++-- Ryujinx.HLE/HOS/Horizon.cs | 10 +++++++--- Ryujinx/Ui/MainWindow.cs | 19 ++++++++++--------- Ryujinx/Ui/MainWindow.glade | 2 +- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs b/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs index 6aed3c5d..afbe56a6 100644 --- a/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs +++ b/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs @@ -395,6 +395,14 @@ namespace Ryujinx.Audio.Renderer.Server Logger.Info?.Print(LogClass.AudioRenderer, $"Stopped renderer id {_sessionId}"); } + public void Disable() + { + lock (_lock) + { + _isActive = false; + } + } + public ResultCode Update(Memory output, Memory performanceOutput, ReadOnlyMemory input) { lock (_lock) diff --git a/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs b/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs index f471a2e7..7518c447 100644 --- a/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs +++ b/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs @@ -219,7 +219,21 @@ namespace Ryujinx.Audio.Renderer.Server /// public void StopSendingCommands() { - _isRunning = false; + lock (_sessionLock) + { + foreach (AudioRenderSystem renderer in _sessions) + { + renderer?.Disable(); + } + } + + lock (_audioProcessorLock) + { + if (_isRunning) + { + StopLocked(); + } + } } /// @@ -234,7 +248,7 @@ namespace Ryujinx.Audio.Renderer.Server { lock (_sessionLock) { - foreach(AudioRenderSystem renderer in _sessions) + foreach (AudioRenderSystem renderer in _sessions) { renderer?.SendCommands(); } diff --git a/Ryujinx.HLE/HOS/Horizon.cs b/Ryujinx.HLE/HOS/Horizon.cs index 76ab1bc4..877bb389 100644 --- a/Ryujinx.HLE/HOS/Horizon.cs +++ b/Ryujinx.HLE/HOS/Horizon.cs @@ -386,10 +386,14 @@ namespace Ryujinx.HLE.HOS _isDisposed = true; // "Soft" stops AudioRenderer and AudioManager to avoid some sound between resume and stop. - AudioRendererManager.StopSendingCommands(); - AudioManager.StopUpdates(); + if (IsPaused) + { + AudioManager.StopUpdates(); - TogglePauseEmulation(false); + TogglePauseEmulation(false); + + AudioRendererManager.StopSendingCommands(); + } KProcess terminationProcess = new KProcess(KernelContext); KThread terminationThread = new KThread(KernelContext); diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index bd3dff95..519e0287 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -214,6 +214,7 @@ namespace Ryujinx.Ui _actionMenu.Sensitive = false; _pauseEmulation.Sensitive = false; + _resumeEmulation.Sensitive = false; if (ConfigurationState.Instance.Ui.GuiColumns.FavColumn) _favToggle.Active = true; if (ConfigurationState.Instance.Ui.GuiColumns.IconColumn) _iconToggle.Active = true; @@ -1289,36 +1290,36 @@ namespace Ryujinx.Ui UpdateGameMetadata(_emulationContext.Application.TitleIdText); } - _pauseEmulation.Visible = true; _pauseEmulation.Sensitive = false; - _resumeEmulation.Visible = false; + _resumeEmulation.Sensitive = false; RendererWidget?.Exit(); } private void PauseEmulation_Pressed(object sender, EventArgs args) { - _pauseEmulation.Visible = false; - _resumeEmulation.Visible = true; + _pauseEmulation.Sensitive = false; + _resumeEmulation.Sensitive = true; _emulationContext.System.TogglePauseEmulation(true); } private void ResumeEmulation_Pressed(object sender, EventArgs args) { - _pauseEmulation.Visible = true; - _resumeEmulation.Visible = false; + _pauseEmulation.Sensitive = true; + _resumeEmulation.Sensitive = false; _emulationContext.System.TogglePauseEmulation(false); } public void ActivatePauseMenu() { _pauseEmulation.Sensitive = true; + _resumeEmulation.Sensitive = false; } public void TogglePause() { - _pauseEmulation.Visible ^= true; - _resumeEmulation.Visible ^= true; - _emulationContext.System.TogglePauseEmulation(_resumeEmulation.Visible); + _pauseEmulation.Sensitive ^= true; + _resumeEmulation.Sensitive ^= true; + _emulationContext.System.TogglePauseEmulation(_resumeEmulation.Sensitive); } private void Installer_File_Pressed(object o, EventArgs args) diff --git a/Ryujinx/Ui/MainWindow.glade b/Ryujinx/Ui/MainWindow.glade index 2fa00688..66b307fb 100644 --- a/Ryujinx/Ui/MainWindow.glade +++ b/Ryujinx/Ui/MainWindow.glade @@ -305,7 +305,7 @@ - False + True False Resume emulation Resume Emulation