From e554456a0051e4b10882796c26e2bbedc7fedbf1 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 17 Jan 2025 14:20:37 +1000 Subject: [PATCH] System: Fix blank display on pause-on-start --- src/core/fullscreen_ui.cpp | 2 +- src/core/hotkeys.cpp | 2 +- src/core/imgui_overlays.cpp | 2 +- src/core/system.cpp | 24 ++++++++++++++---------- src/core/system.h | 2 +- src/duckstation-qt/qthost.cpp | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 486809b7e..1d6b15a23 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -7165,7 +7165,7 @@ void FullscreenUI::DoLoadState(std::string path) else { Error error; - if (!System::LoadState(path.c_str(), &error, true)) + if (!System::LoadState(path.c_str(), &error, true, false)) { GPUThread::RunOnThread([error_desc = error.TakeDescription()]() { ShowToast(std::string(), fmt::format(TRANSLATE_FS("System", "Failed to load state: {}"), error_desc)); diff --git a/src/core/hotkeys.cpp b/src/core/hotkeys.cpp index c8e53eeb7..7d60ea83b 100644 --- a/src/core/hotkeys.cpp +++ b/src/core/hotkeys.cpp @@ -88,7 +88,7 @@ static void HotkeyLoadStateSlot(bool global, s32 slot) } Error error; - if (!System::LoadState(path.c_str(), &error, true)) + if (!System::LoadState(path.c_str(), &error, true, false)) { Host::AddKeyedOSDMessage( "LoadState", diff --git a/src/core/imgui_overlays.cpp b/src/core/imgui_overlays.cpp index e87b72969..e0050629d 100644 --- a/src/core/imgui_overlays.cpp +++ b/src/core/imgui_overlays.cpp @@ -1282,7 +1282,7 @@ void SaveStateSelectorUI::LoadCurrentSlot() { Host::RunOnCPUThread([path = std::move(path)]() { Error error; - if (!System::LoadState(path.c_str(), &error, true)) + if (!System::LoadState(path.c_str(), &error, true, false)) { Host::AddKeyedOSDMessage("LoadState", fmt::format(TRANSLATE_FS("OSDMessage", "Failed to load state from slot {0}:\n{1}"), diff --git a/src/core/system.cpp b/src/core/system.cpp index eedfe27df..6963b4848 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1823,8 +1823,11 @@ bool System::BootSystem(SystemBootParameters parameters, Error* error) std::atomic_thread_fence(std::memory_order_release); SPU::GetOutputStream()->SetPaused(false); + // Immediately pausing? + const bool start_paused = (ShouldStartPaused() || parameters.override_start_paused.value_or(false)); + // try to load the state, if it fails, bail out - if (!parameters.save_state.empty() && !LoadState(parameters.save_state.c_str(), error, false)) + if (!parameters.save_state.empty() && !LoadState(parameters.save_state.c_str(), error, false, start_paused)) { Error::AddPrefixFmt(error, "Failed to load save state file '{}' for booting:\n", Path::GetFileName(parameters.save_state)); @@ -1852,7 +1855,7 @@ bool System::BootSystem(SystemBootParameters parameters, Error* error) if (parameters.start_media_capture) StartMediaCapture({}); - if (ShouldStartPaused() || parameters.override_start_paused.value_or(false)) + if (start_paused) PauseSystem(true); UpdateSpeedLimiterState(); @@ -2808,7 +2811,7 @@ std::string System::GetMediaPathFromSaveState(const char* path) return std::move(buffer.media_path); } -bool System::LoadState(const char* path, Error* error, bool save_undo_state) +bool System::LoadState(const char* path, Error* error, bool save_undo_state, bool force_update_display) { if (!IsValid() || IsReplayingGPUDump()) { @@ -2818,11 +2821,12 @@ bool System::LoadState(const char* path, Error* error, bool save_undo_state) if (Achievements::IsHardcoreModeActive()) { - Achievements::ConfirmHardcoreModeDisableAsync(TRANSLATE("Achievements", "Loading state"), - [path = std::string(path), save_undo_state](bool approved) { - if (approved) - LoadState(path.c_str(), nullptr, save_undo_state); - }); + Achievements::ConfirmHardcoreModeDisableAsync( + TRANSLATE("Achievements", "Loading state"), + [path = std::string(path), save_undo_state, force_update_display](bool approved) { + if (approved) + LoadState(path.c_str(), nullptr, save_undo_state, force_update_display); + }); return true; } @@ -2849,7 +2853,7 @@ bool System::LoadState(const char* path, Error* error, bool save_undo_state) SaveStateBuffer buffer; if (!LoadStateBufferFromFile(&buffer, fp.get(), error, false, true, false, true) || - !LoadStateFromBuffer(buffer, error, IsPaused())) + !LoadStateFromBuffer(buffer, error, force_update_display || IsPaused())) { if (save_undo_state) UndoLoadState(); @@ -2950,7 +2954,7 @@ bool System::LoadStateDataFromBuffer(std::span data, u32 version, Erro ResetThrottler(); if (update_display) - GPUThread::PresentCurrentFrame(); + g_gpu.UpdateDisplay(true); return true; } diff --git a/src/core/system.h b/src/core/system.h index 8d9a77c1a..3cf68b974 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -259,7 +259,7 @@ void ResetSystem(); size_t GetMaxSaveStateSize(); /// Loads state from the specified path. -bool LoadState(const char* path, Error* error, bool save_undo_state); +bool LoadState(const char* path, Error* error, bool save_undo_state, bool force_update_display); bool SaveState(std::string path, Error* error, bool backup_existing_save, bool ignore_memcard_busy); bool SaveResumeState(Error* error); diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 6eaa30538..fd609faa0 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -806,7 +806,7 @@ void EmuThread::bootOrLoadState(std::string path) if (System::IsValid()) { Error error; - if (!System::LoadState(path.c_str(), &error, true)) + if (!System::LoadState(path.c_str(), &error, true, false)) { emit errorReported(tr("Error"), tr("Failed to load state: %1").arg(QString::fromStdString(error.GetDescription())));