From c393db6fdc5ccc7fdbd8bd336b18fb33b9bf34ec Mon Sep 17 00:00:00 2001 From: Roman Zhu Date: Sun, 30 Aug 2026 22:13:27 +0200 Subject: [PATCH] Fix asset file race https://github.com/RomanZhu/FlaxEngine/commit/71bad36469bc6cdd31384f429bdc05c251e0eb91 --- Source/Engine/Content/Storage/FlaxStorage.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Content/Storage/FlaxStorage.cpp b/Source/Engine/Content/Storage/FlaxStorage.cpp index 4eaea48f8..b7be69468 100644 --- a/Source/Engine/Content/Storage/FlaxStorage.cpp +++ b/Source/Engine/Content/Storage/FlaxStorage.cpp @@ -1438,10 +1438,6 @@ FileReadStream* FlaxStorage::OpenFile() bool FlaxStorage::CloseFileHandles() { - // Guard the whole process so if new thread wants to lock the chunks will need to wait for this to end - Platform::InterlockedIncrement(&_isUnloadingData); - SCOPE_EXIT{ Platform::InterlockedDecrement(&_isUnloadingData); }; - if (Platform::AtomicRead(&_chunksLock) == 0 && Platform::AtomicRead(&_files) == 0) return false; // Early out when no files are opened PROFILE_CPU(); @@ -1469,7 +1465,13 @@ bool FlaxStorage::CloseFileHandles() } } } - waitTime = 100; + + // Guard the whole process so if new thread wants to lock the chunks will need to wait for this to end + Platform::InterlockedIncrement(&_isUnloadingData); + SCOPE_EXIT{ Platform::InterlockedDecrement(&_isUnloadingData); }; + + // Wait for chunks lock again (with larger timeout for longer tasks) + waitTime = 1000; while (Platform::AtomicRead(&_chunksLock) != 0 && waitTime-- > 0) Platform::Sleep(1); if (Platform::AtomicRead(&_chunksLock) != 0)