From c7b1c8b155600396c996fb88f359990839977797 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 6 Apr 2023 19:01:07 +0200 Subject: [PATCH] Core/AppFilesystemComponent: Fix Open with physical files --- include/Nazara/Core/AppFilesystemComponent.inl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/Nazara/Core/AppFilesystemComponent.inl b/include/Nazara/Core/AppFilesystemComponent.inl index 96a71c3ec..3e584a776 100644 --- a/include/Nazara/Core/AppFilesystemComponent.inl +++ b/include/Nazara/Core/AppFilesystemComponent.inl @@ -162,7 +162,13 @@ namespace Nz } else if constexpr (std::is_same_v) { - resource = T::OpenFromStream(*arg.stream, params, std::forward(args)...); + // If stream has an associated filesystem path, use OpenFromFile instead to make sure the File stream is kept alive + // (a temporary FileEntry may be created when resolving a filesystem folder) + if (std::filesystem::path filePath = arg.stream->GetPath(); !filePath.empty()) + resource = T::OpenFromFile(*arg.stream, params, std::forward(args)...); + else + resource = T::OpenFromStream(*arg.stream, params, std::forward(args)...); + return true; } else