From 777602fee6ae6f6d5d41b2b188811677c5bc29b5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 2 Jun 2026 15:54:36 +0200 Subject: [PATCH] Fix asset storage handling when file is locked https://github.com/LOOPDISK/FlaxEngine/pull/45 --- Source/Engine/Content/BinaryAsset.cpp | 5 +---- Source/Engine/Content/Cache/AssetsCache.cpp | 4 ++-- Source/Engine/Content/Storage/ContentStorageManager.cpp | 4 ++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Content/BinaryAsset.cpp b/Source/Engine/Content/BinaryAsset.cpp index 04fb3c3cf..c79e011b2 100644 --- a/Source/Engine/Content/BinaryAsset.cpp +++ b/Source/Engine/Content/BinaryAsset.cpp @@ -564,10 +564,7 @@ ContentLoadTask* BinaryAsset::createLoadingTask() loadTask = preLoadChunksTask; } - // Before asset loading we have to initialize storage - // TODO: maybe in build game we could do it in place? - // This step is only for opening asset files in background and upgrading them - // In build game we have only a few packages which are ready to use + // Before asset loading we have to initialize storage and pull the asset header auto initTask = New(this); initTask->ContinueWith(loadTask); loadTask = initTask; diff --git a/Source/Engine/Content/Cache/AssetsCache.cpp b/Source/Engine/Content/Cache/AssetsCache.cpp index e36a0d76c..96da061f1 100644 --- a/Source/Engine/Content/Cache/AssetsCache.cpp +++ b/Source/Engine/Content/Cache/AssetsCache.cpp @@ -378,13 +378,13 @@ void AssetsCache::GetAllByTypeName(const StringView& typeName, Array& resu void AssetsCache::RegisterAssets(FlaxStorage* storage) { PROFILE_CPU(); - ASSERT(storage); // Get all entries Array entries; storage->GetEntries(entries); - ASSERT(entries.HasItems()); + if (entries.IsEmpty()) + return; ASSETS_CACHE_LOCK(); auto storagePath = storage->GetPath(); diff --git a/Source/Engine/Content/Storage/ContentStorageManager.cpp b/Source/Engine/Content/Storage/ContentStorageManager.cpp index 8aa36c7be..33a16e031 100644 --- a/Source/Engine/Content/Storage/ContentStorageManager.cpp +++ b/Source/Engine/Content/Storage/ContentStorageManager.cpp @@ -54,6 +54,7 @@ FlaxStorageReference ContentStorageManager::GetStorage(const StringView& path, b Locker.Lock(); // Try fast lookup + bool wasCached = true; FlaxStorage* storage; if (!StorageMap.TryGet(path, storage)) { @@ -74,6 +75,7 @@ FlaxStorageReference ContentStorageManager::GetStorage(const StringView& path, b // Register storage container StorageMap.Add(path, storage); + wasCached = false; } // Build reference (before releasing the lock so ContentStorageSystem::Job won't delete it when running from async thread) @@ -90,6 +92,8 @@ FlaxStorageReference ContentStorageManager::GetStorage(const StringView& path, b if (loadFailed) { LOG(Error, "Failed to load {0}.", path); + if (wasCached) + return result; Locker.Lock(); StorageMap.Remove(path); if (storage->IsPackage())