From 42c6c4420ba2b886cc776bf57dd8723d9ed46eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 11 Nov 2026 13:46:31 +0100 Subject: [PATCH] Pause menu: Show a slot as busy while its save is being written On a slow device, pausing again right after saving a state could show the slot's Save and Load buttons enabled while the save was still being written. The slot now has its buttons and screenshot disabled, with a spinner, until the save ends, and the menu refreshes then. The refresh message is now posted when a save ends any way (written, failed or refused), after it has left the pending list, so the refresh can't still see it as pending. Co-Authored-By: Claude Opus 5.5 --- Common/System/System.h | 2 +- Core/SaveState.cpp | 19 ++++++++++++++----- Core/SaveState.h | 2 ++ UI/PauseScreen.cpp | 11 +++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Common/System/System.h b/Common/System/System.h index 3d15195ca2..d776adf192 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -330,7 +330,7 @@ enum class UIMessage { RECENT_FILES_CHANGED, SAVE_FRAME_DUMP, ADHOC_SERVER_LIST_CHANGED, - SAVESTATE_SLOT_SAVED, // A slot's save state file was written. + SAVESTATE_SLOT_SAVED, // A save state save finished: written, failed or refused. SOFT_KEYBOARD_HIDDEN, // The platform closed a soft keyboard forced by System_SetSoftKeyboardForced. }; diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index fb6bcbbacf..359a48b451 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -454,9 +454,16 @@ int g_screenshotFailures; // A save is done (written, failed or refused). Returns the callbacks of its repeats. static std::vector FinishPendingSave(const std::shared_ptr &save) { - std::lock_guard guard(mutex); - g_pendingSaves.erase(std::remove(g_pendingSaves.begin(), g_pendingSaves.end(), save), g_pendingSaves.end()); - return std::move(save->repeats); + std::vector repeats; + { + std::lock_guard guard(mutex); + g_pendingSaves.erase(std::remove(g_pendingSaves.begin(), g_pendingSaves.end(), save), g_pendingSaves.end()); + repeats = std::move(save->repeats); + } + // The pause screen shows a slot with a save pending as busy, or listed it before the file was there. + // Posted after the save left the pending list, so the refresh doesn't still see it. + System_PostUIMessage(UIMessage::SAVESTATE_SLOT_SAVED); + return repeats; } static void RefuseOperation(const Operation &op) { @@ -935,6 +942,10 @@ int g_screenshotFailures; return g_files.find(GenerateSaveSlotFilename(gamePrefix, slot, extension)) != g_files.end(); } + bool IsSlotSavePending(std::string_view gamePrefix, int slot) { + return IsSavePending(GenerateSaveSlotPath(gamePrefix, slot, STATE_EXTENSION)); + } + bool HasSaveInSlot(std::string_view gamePrefix, int slot) { return SaveStateFileExists(gamePrefix, slot, STATE_EXTENSION); } @@ -1254,8 +1265,6 @@ int g_screenshotFailures; g_Config.Save("Saving config for savestate last save undo"); } g_filesStale = true; - // The pause screen may have listed the slots before the file was there. - System_PostUIMessage(UIMessage::SAVESTATE_SLOT_SAVED); } } else { if (result == CChunkFileReader::ERROR_BROKEN_STATE) { diff --git a/Core/SaveState.h b/Core/SaveState.h index 8ecbd6e101..9636057e4d 100644 --- a/Core/SaveState.h +++ b/Core/SaveState.h @@ -68,6 +68,8 @@ namespace SaveState { // Checks whether there's an existing save in the specified slot. bool HasSaveInSlot(std::string_view gamePrefix, int slot); + // A save to the slot was asked for and isn't written yet. UIMessage::SAVESTATE_SLOT_SAVED says when it ends. + bool IsSlotSavePending(std::string_view gamePrefix, int slot); bool HasUndoSaveInSlot(std::string_view gamePrefix, int slot); bool HasUndoLastSave(std::string_view gamePrefix); bool HasUndoLoad(std::string_view gamePrefix); diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index ac48ce9c4f..fc39244fe4 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -311,11 +311,18 @@ SaveSlotView::SaveSlotView(std::string_view saveStatePrefix, int slot, UI::Layou OnScreenshotClicked.Trigger(e); }); + // A save to this slot is still being written (slow storage, a save asked for just before the menu + // opened). The screen is rebuilt when it finishes, on UIMessage::SAVESTATE_SLOT_SAVED. + const bool savePending = SaveState::IsSlotSavePending(saveStatePrefix_, slot_); + saveStateButton_->SetEnabled(!savePending); + fv->SetEnabled(!savePending); + if (SaveState::HasSaveInSlot(saveStatePrefix_, slot_)) { if (!Achievements::HardcoreModeActive()) { loadStateButton_ = buttons->Add(new Button(pa->T("Load State"), new LinearLayoutParams(0.0, Gravity::G_VCENTER))); loadStateButton_->OnClick.Handle(this, &SaveSlotView::OnLoadState); loadStateButton_->SetRoundCorners(); + loadStateButton_->SetEnabled(!savePending); } std::string nameStr = SaveState::GetSlotCustomName(saveStatePrefix_, slot_); @@ -340,6 +347,10 @@ SaveSlotView::SaveSlotView(std::string_view saveStatePrefix, int slot, UI::Layou } else { fv->SetFilename(Path()); } + + if (savePending) { + buttons->Add(new Spinner(nullptr, 0, new LinearLayoutParams(32.0f, 32.0f, 0.0f, Gravity::G_VCENTER))); + } } void SaveSlotView::Draw(UIContext &dc) {