From 269f01f841215503b881eae75798e9534cd6a2eb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 2 Apr 2023 12:17:59 -0700 Subject: [PATCH] SaveState: Attempt to recover from missing files. If there were files open before that don't exist, things could go badly. But we could at least load the state file and hope the game doesn't break. That's better that refusing to load at all. --- Core/FileSystems/DirectoryFileSystem.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 19908b5ac1..d0d7de770a 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -906,20 +906,25 @@ void DirectoryFileSystem::DoState(PointerWrap &p) { Do(p, entry.guestFilename); Do(p, entry.access); u32 err; + bool brokenFile = false; if (!entry.hFile.Open(basePath,entry.guestFilename,entry.access, err)) { ERROR_LOG(FILESYS, "Failed to reopen file while loading state: %s", entry.guestFilename.c_str()); - continue; + brokenFile = true; } u32 position; Do(p, position); if (position != entry.hFile.Seek(position, FILEMOVE_BEGIN)) { ERROR_LOG(FILESYS, "Failed to restore seek position while loading state: %s", entry.guestFilename.c_str()); - continue; + brokenFile = true; } if (s >= 2) { Do(p, entry.hFile.needsTrunc_); } - entries[key] = entry; + // Let's hope that things don't go that badly with the file mysteriously auto-closed. + // Better than not loading the save state at all, hopefully. + if (!brokenFile) { + entries[key] = entry; + } } } else { for (auto iter = entries.begin(); iter != entries.end(); ++iter) {