From fc32d795965f39b9db929a7ba4d16752696c0520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 28 Sep 2026 11:21:22 -0600 Subject: [PATCH] Savestate: Fix reopening files on load Drop an ISO handle whose file isn't in the loaded image instead of keeping a null file, and don't reopen a directory file with exclusive create. Co-Authored-By: Claude Opus 5.5 (1M context) --- Core/FileSystems/DirectoryFileSystem.cpp | 3 ++- Core/FileSystems/ISOFileSystem.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 411f1161a8..9435a0e970 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -1093,7 +1093,8 @@ void DirectoryFileSystem::DoState(PointerWrap &p) { Do(p, entry.guestFilename); Do(p, entry.access); u32 err; - bool opened = entry.hFile.Open(basePath, entry.guestFilename, entry.access, err); + // The original open created the file, so an exclusive create would fail now. + bool opened = entry.hFile.Open(basePath, entry.guestFilename, (FileAccess)(entry.access & ~FILEACCESS_EXCL), err); bool brokenFile = !opened; if (!opened) { ERROR_LOG(Log::FileSystem, "Failed to reopen file while loading state: %s", entry.guestFilename.c_str()); diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index b0ccb9ec22..aae8acc549 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -857,6 +857,12 @@ void ISOFileSystem::DoState(PointerWrap &p) { std::string path; Do(p, path); of.file = GetFromPath(path); + if (!of.file) { + // Loaded against a different image. Like a file that's gone from a directory, + // drop the handle rather than keep one that points at nothing. + ERROR_LOG(Log::FileSystem, "Failed to reopen file while loading state: %s", path.c_str()); + continue; + } } else { of.file = NULL; }