Fix possible infinite recursion in asset catalog tree building #118463

Merged
Julian Eisel merged 4 commits from JulianEisel/blender:temp-asset-library-tag-catalogs-dirty into main 2024-02-21 13:02:48 +01:00
10 changed files with 48 additions and 9 deletions

View File

@ -179,6 +179,7 @@ class AssetLibrary {
Vector<AssetLibraryReference> all_valid_asset_library_refs();
AssetLibraryReference all_library_reference();
void all_library_reload_catalogs_if_dirty();
} // namespace blender::asset_system

View File

@ -238,7 +238,7 @@ void AssetCatalogService::prune_catalogs_by_path(const AssetCatalogPath &path)
}
this->rebuild_tree();
AssetLibraryService::get()->rebuild_all_library();
AssetLibraryService::get()->tag_all_library_catalogs_dirty();
}
void AssetCatalogService::prune_catalogs_by_id(const CatalogID catalog_id)
@ -273,7 +273,7 @@ void AssetCatalogService::update_catalog_path(const CatalogID catalog_id,
}
this->rebuild_tree();
AssetLibraryService::get()->rebuild_all_library();
AssetLibraryService::get()->tag_all_library_catalogs_dirty();
}
AssetCatalog *AssetCatalogService::create_catalog(const AssetCatalogPath &catalog_path)
@ -299,8 +299,7 @@ AssetCatalog *AssetCatalogService::create_catalog(const AssetCatalogPath &catalo
BLI_assert_msg(catalog_tree_, "An Asset Catalog tree should always exist.");
catalog_tree_->insert_item(*catalog_ptr);
AssetLibraryService::get()->rebuild_all_library();
AssetLibraryService::get()->tag_all_library_catalogs_dirty();
return catalog_ptr;
}
@ -655,7 +654,7 @@ void AssetCatalogService::undo()
redo_snapshots_.append(std::move(catalog_collection_));
catalog_collection_ = undo_snapshots_.pop_last();
this->rebuild_tree();
AssetLibraryService::get()->rebuild_all_library();
AssetLibraryService::get()->tag_all_library_catalogs_dirty();
}
void AssetCatalogService::redo()
@ -666,7 +665,7 @@ void AssetCatalogService::redo()
undo_snapshots_.append(std::move(catalog_collection_));
catalog_collection_ = redo_snapshots_.pop_last();
this->rebuild_tree();
AssetLibraryService::get()->rebuild_all_library();
AssetLibraryService::get()->tag_all_library_catalogs_dirty();
}
void AssetCatalogService::undo_push()

View File

@ -340,4 +340,10 @@ AssetLibraryReference all_library_reference()
return all_library_ref;
}
void all_library_reload_catalogs_if_dirty()
{
AssetLibraryService *service = AssetLibraryService::get();
service->reload_all_library_catalogs_if_dirty();
}
} // namespace blender::asset_system

View File

@ -57,7 +57,19 @@ void AllAssetLibrary::rebuild_catalogs_from_nested(const bool reload_nested_cata
false);
new_catalog_service->rebuild_tree();
this->catalog_service = std::move(new_catalog_service);
catalogs_dirty_ = false;
}
void AllAssetLibrary::tag_catalogs_dirty()
{
catalogs_dirty_ = true;
}
bool AllAssetLibrary::is_catalogs_dirty()
{
return catalogs_dirty_;
}
void AllAssetLibrary::refresh_catalogs()

View File

@ -13,6 +13,8 @@
namespace blender::asset_system {
class AllAssetLibrary : public AssetLibrary {
bool catalogs_dirty_ = true;
public:
AllAssetLibrary();
@ -26,6 +28,9 @@ class AllAssetLibrary : public AssetLibrary {
* merge them into the in-memory representations.
*/
void rebuild_catalogs_from_nested(bool reload_nested_catalogs);
void tag_catalogs_dirty();
bool is_catalogs_dirty();
};
} // namespace blender::asset_system

View File

@ -187,10 +187,17 @@ AssetLibrary *AssetLibraryService::get_asset_library_current_file()
return lib;
}
void AssetLibraryService::rebuild_all_library()
void AssetLibraryService::tag_all_library_catalogs_dirty()
{
if (all_library_) {
all_library_->rebuild_catalogs_from_nested(false);
all_library_->tag_catalogs_dirty();
}
}
void AssetLibraryService::reload_all_library_catalogs_if_dirty()
{
if (all_library_ && all_library_->is_catalogs_dirty()) {
all_library_->refresh_catalogs();
}
}

View File

@ -88,7 +88,13 @@ class AssetLibraryService {
AssetLibrary *get_asset_library_current_file();
/** Get the "All" asset library, which loads all others and merges them into one. */
AssetLibrary *get_asset_library_all(const Main *bmain);
void rebuild_all_library();
/**
* Tag the "All" asset library as needing to reload catalogs. This should be called when catalog
* data of other asset libraries changes. Note that changes to the catalog definition file on
* disk don't ever affect this "dirty" flag. It only reflects changes from this Blender session.
*/
void tag_all_library_catalogs_dirty();
void reload_all_library_catalogs_if_dirty();
/**
* Return the start position of the last blend-file extension in given path,

View File

@ -785,6 +785,7 @@ static asset::AssetItemTree build_catalog_tree(const bContext &C, const Object &
return true;
};
const AssetLibraryReference library = asset_system::all_library_reference();
asset_system::all_library_reload_catalogs_if_dirty();
return asset::build_filtered_all_catalog_tree(library, C, type_filter, meta_data_filter);
}

View File

@ -65,6 +65,7 @@ static asset::AssetItemTree build_catalog_tree(const bContext &C)
return true;
};
const AssetLibraryReference library = asset_system::all_library_reference();
asset_system::all_library_reload_catalogs_if_dirty();
return asset::build_filtered_all_catalog_tree(library, C, type_filter, meta_data_filter);
}

View File

@ -51,6 +51,7 @@ static asset::AssetItemTree build_catalog_tree(const bContext &C, const bNodeTre
return true;
};
const AssetLibraryReference library = asset_system::all_library_reference();
asset_system::all_library_reload_catalogs_if_dirty();
return asset::build_filtered_all_catalog_tree(library, C, type_filter, meta_data_filter);
}