From 7705e49bcdeb779b6d49580fbc0a0c753b0ba6d6 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Fri, 13 Oct 2023 18:52:38 +0200 Subject: [PATCH] Fix #113201: Assets in same folder as current file ignored in All library If an asset library was pointing to the same path as the current file is saved in, the assets from this library wouldn't be loaded. This is because the asset library service assumed the absolute library root path is a way to uniquely identify an asset library. Instead, identify the asset library using both the root path and the library type. --- .../asset_system/intern/asset_library_service.cc | 4 ++-- .../asset_system/intern/asset_library_service.hh | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/blender/asset_system/intern/asset_library_service.cc b/source/blender/asset_system/intern/asset_library_service.cc index f6cf698eb7e..161cd59c01a 100644 --- a/source/blender/asset_system/intern/asset_library_service.cc +++ b/source/blender/asset_system/intern/asset_library_service.cc @@ -122,7 +122,7 @@ AssetLibrary *AssetLibraryService::get_asset_library_on_disk(eAssetLibraryType l std::string normalized_root_path = utils::normalize_directory_path(root_path); std::unique_ptr *lib_uptr_ptr = on_disk_libraries_.lookup_ptr( - normalized_root_path); + {library_type, normalized_root_path}); if (lib_uptr_ptr != nullptr) { CLOG_INFO(&LOG, 2, "get \"%s\" (cached)", normalized_root_path.c_str()); AssetLibrary *lib = lib_uptr_ptr->get(); @@ -139,7 +139,7 @@ AssetLibrary *AssetLibraryService::get_asset_library_on_disk(eAssetLibraryType l /* Reload catalogs on refresh. */ lib->on_refresh_ = [](AssetLibrary &self) { self.catalog_service->reload_catalogs(); }; - on_disk_libraries_.add_new(normalized_root_path, std::move(lib_uptr)); + on_disk_libraries_.add_new({library_type, normalized_root_path}, std::move(lib_uptr)); CLOG_INFO(&LOG, 2, "get \"%s\" (loaded)", normalized_root_path.c_str()); return lib; } diff --git a/source/blender/asset_system/intern/asset_library_service.hh b/source/blender/asset_system/intern/asset_library_service.hh index afbc1da14cf..8b27f532cea 100644 --- a/source/blender/asset_system/intern/asset_library_service.hh +++ b/source/blender/asset_system/intern/asset_library_service.hh @@ -9,6 +9,7 @@ #pragma once #include +#include #include "AS_asset_library.hh" @@ -38,9 +39,12 @@ namespace blender::asset_system { class AssetLibraryService { static std::unique_ptr instance_; - /* Mapping absolute path of the library's root path (normalize with #normalize_directory_path()!) - * the AssetLibrary instance. */ - Map> on_disk_libraries_; + /** Identify libraries with the library type, and the absolute path of the library's root path + * (normalize with #normalize_directory_path()!). The type is relevant since the current file + * library may point to the same path as a custom library. */ + using OnDiskLibraryIdentifier = std::pair; + /* Mapping of a (type, root path) pair to the AssetLibrary instance. */ + Map> on_disk_libraries_; /** Library without a known path, i.e. the "Current File" library if the file isn't saved yet. If * the file was saved, a valid path for the library can be determined and #on_disk_libraries_ * above should be used. */