From c86355d59299532ca08ce9c97048a9ae5647ee35 Mon Sep 17 00:00:00 2001 From: Thierry Crozat Date: Tue, 16 Feb 2021 03:12:08 +0000 Subject: [PATCH] AGS: Fix assert when trying to open file that does not exist --- engines/ags/shared/util/stdio_compat.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/engines/ags/shared/util/stdio_compat.cpp b/engines/ags/shared/util/stdio_compat.cpp index 4ec29b290b0..f6b75a497ac 100644 --- a/engines/ags/shared/util/stdio_compat.cpp +++ b/engines/ags/shared/util/stdio_compat.cpp @@ -84,11 +84,15 @@ Common::FSNode getFSNode(const char *path) { return dir->getFSNode().getChild(file->getName()); } - dir.reset(dir->getSubDirectory(filePath)); - if (dir) + Common::FSDirectory *subDir = dir->getSubDirectory(filePath); + if (subDir) { + dir.reset(subDir); return dir->getFSNode(); + } - return Common::FSNode(); + // The files does not exist, but create the FSNode anyway so that + // the code using this can report the correct error rather than assert. + return dir->getFSNode().getChild(filePath); } int ags_file_exists(const char *path) {