From e504973cf00072887167484adb66ad0b22d372b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 20 Jul 2024 00:17:31 +0200 Subject: [PATCH] On load state failure, don't go off reloading another rewind state, unless we were actually rewinding. --- Common/Render/ManagedTexture.cpp | 2 +- Core/SaveState.cpp | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Common/Render/ManagedTexture.cpp b/Common/Render/ManagedTexture.cpp index deb3d4f4b1..027abd2b77 100644 --- a/Common/Render/ManagedTexture.cpp +++ b/Common/Render/ManagedTexture.cpp @@ -32,7 +32,7 @@ public: size_t fileSize; uint8_t *buffer = g_VFS.ReadFile(filename_.c_str(), &fileSize); if (!buffer) { - ERROR_LOG(Log::IO, "Failed to read file '%s'", filename_.c_str()); + WARN_LOG(Log::IO, "Failed to read file '%s'", filename_.c_str()); filename_.clear(); *state_ = ManagedTexture::LoadState::FAILED; waitable_->Notify(); diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 202fdaf972..49ac73c0af 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -835,20 +835,21 @@ namespace SaveState return copy; } - bool HandleLoadFailure() + bool HandleLoadFailure(bool wasRewinding) { - WARN_LOG(Log::SaveState, "HandleLoadFailure - trying a rewind state."); + if (wasRewinding) { + WARN_LOG(Log::SaveState, "HandleLoadFailure - trying a rewind state."); + // Okay, first, let's give the next rewind state a shot - maybe we can at least not reset entirely. + // Actually, this seems like a bad thing - some systems can end up in bad states, like sceFont :( + CChunkFileReader::Error result; + do { + std::string errorString; + result = rewindStates.Restore(&errorString); + } while (result == CChunkFileReader::ERROR_BROKEN_STATE); - // Okay, first, let's give the rewind state a shot - maybe we can at least not reset entirely. - // Even if this was a rewind, maybe we can still load a previous one. - CChunkFileReader::Error result; - do { - std::string errorString; - result = rewindStates.Restore(&errorString); - } while (result == CChunkFileReader::ERROR_BROKEN_STATE); - - if (result == CChunkFileReader::ERROR_NONE) { - return true; + if (result == CChunkFileReader::ERROR_NONE) { + return true; + } } // We tried, our only remaining option is to reset the game. @@ -972,7 +973,7 @@ namespace SaveState } #endif } else if (result == CChunkFileReader::ERROR_BROKEN_STATE) { - HandleLoadFailure(); + HandleLoadFailure(false); callbackMessage = std::string(i18nLoadFailure) + ": " + errorString; ERROR_LOG(Log::SaveState, "Load state failure: %s", errorString.c_str()); callbackResult = Status::FAILURE; @@ -1037,7 +1038,7 @@ namespace SaveState Core_ResetException(); } else if (result == CChunkFileReader::ERROR_BROKEN_STATE) { // Cripes. Good news is, we might have more. Let's try those too, better than a reset. - if (HandleLoadFailure()) { + if (HandleLoadFailure(true)) { // Well, we did rewind, even if too much... callbackMessage = sc->T("Loaded State"); callbackResult = Status::SUCCESS;