From a3ab7cd14e66456f006cc71f07ebaa2309ea2958 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 16 May 2023 11:52:49 +0200 Subject: [PATCH] Fix file lock when loading asset fails #1103 --- Source/Engine/Content/Content.cpp | 7 ++++++- Source/Engine/Content/Storage/FlaxStorage.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index e58aa458d..d57529b92 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -760,9 +760,14 @@ bool Content::CloneAssetFile(const StringView& dstPath, const StringView& srcPat // Change asset ID { auto storage = ContentStorageManager::GetStorage(tmpPath); + if (!storage) + { + LOG(Warning, "Cannot change asset ID."); + return true; + } FlaxStorage::Entry e; storage->GetEntry(0, e); - if (!storage || storage->ChangeAssetID(e, dstId)) + if (storage->ChangeAssetID(e, dstId)) { LOG(Warning, "Cannot change asset ID."); return true; diff --git a/Source/Engine/Content/Storage/FlaxStorage.cpp b/Source/Engine/Content/Storage/FlaxStorage.cpp index 8608a34f6..52d7c34b5 100644 --- a/Source/Engine/Content/Storage/FlaxStorage.cpp +++ b/Source/Engine/Content/Storage/FlaxStorage.cpp @@ -211,6 +211,12 @@ FlaxStorage::~FlaxStorage() CHECK(_chunksLock == 0); CHECK(_refCount == 0); ASSERT(_chunks.IsEmpty()); + +#if USE_EDITOR + // Ensure to close any outstanding file handles to prevent file locking in case it failed to load + _file.DeleteAll(); +#endif + } FlaxStorage::LockData FlaxStorage::LockSafe()