From d65ae8de96d46a5d09bfdbea6da39dda759f0d8c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 22 Mar 2021 20:04:57 +0100 Subject: [PATCH] Fix saving assets with path containing invalid slashes --- Source/Engine/Content/BinaryAsset.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Content/BinaryAsset.cpp b/Source/Engine/Content/BinaryAsset.cpp index 1dbc672f2..c0e2057ca 100644 --- a/Source/Engine/Content/BinaryAsset.cpp +++ b/Source/Engine/Content/BinaryAsset.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #include "BinaryAsset.h" +#include "Cache/AssetsCache.h" #include "Storage/ContentStorageManager.h" #include "Loading/Tasks/LoadAssetDataTask.h" #include "Engine/ContentImporters/AssetsImportingManager.h" @@ -303,9 +304,13 @@ bool BinaryAsset::SaveAsset(const StringView& path, AssetInitData& data, bool si bool BinaryAsset::SaveToAsset(const StringView& path, AssetInitData& data, bool silentMode) { + // Ensure path is in a valid format + String pathNorm(path); + FileSystem::NormalizePath(pathNorm); + // Find target storage container and the asset - auto storage = ContentStorageManager::TryGetStorage(path); - auto asset = Content::GetAsset(path); + auto storage = ContentStorageManager::TryGetStorage(pathNorm); + auto asset = Content::GetAsset(pathNorm); auto binaryAsset = dynamic_cast(asset); if (asset && !binaryAsset) { @@ -351,12 +356,18 @@ bool BinaryAsset::SaveToAsset(const StringView& path, AssetInitData& data, bool } else { - ASSERT(path.HasChars()); - result = FlaxStorage::Create(path, data, silentMode); + ASSERT(pathNorm.HasChars()); + result = FlaxStorage::Create(pathNorm, data, silentMode); } if (binaryAsset) binaryAsset->_isSaving = false; + if (!result) + { + // Ensure to have valid cached data about the asset in the registry + Content::GetRegistry()->RegisterAsset(data.Header, pathNorm); + } + return result; }