Skip to content

Commit

Permalink
System: Fix blank display on pause-on-start
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 17, 2025
1 parent 3be4f19 commit e554456
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/core/fullscreen_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/core/hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/core/imgui_overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
Expand Down
24 changes: 14 additions & 10 deletions src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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())
{
Expand All @@ -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;
}

Expand All @@ -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();
Expand Down Expand Up @@ -2950,7 +2954,7 @@ bool System::LoadStateDataFromBuffer(std::span<const u8> data, u32 version, Erro
ResetThrottler();

if (update_display)
GPUThread::PresentCurrentFrame();
g_gpu.UpdateDisplay(true);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/duckstation-qt/qthost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())));
Expand Down

0 comments on commit e554456

Please sign in to comment.