Fix: Assets: Asset library not loaded after creating brush asset (asserts)

The steps in #132900 would lead to a failed assert and some warning prints:
"Warning: Asset loading is unfinished". This is because asset libraries get
cleared more strictly and correctly since a859ed1130, but only once the menu
was shown it would get reloaded.

Instead make sure the asset library loading gets triggered whenever a button to
popup a brush asset shelf is present. This makes sense because in this context
you typically want an asset library available.
This commit is contained in:
Julian Eisel
2025-01-15 19:01:51 +01:00
parent 7fb3179c1f
commit c07b253265
3 changed files with 28 additions and 1 deletions

View File

@@ -91,6 +91,7 @@ AssetShelfType *type_find_from_idname(const StringRef idname);
* \{ */
void type_popup_unlink(const AssetShelfType &shelf_type);
void ensure_asset_library_fetched(const bContext &C, const AssetShelfType &shelf_type);
/** \} */

View File

@@ -6,6 +6,8 @@
* \ingroup edasset
*/
#include "AS_asset_library.hh"
#include "asset_shelf.hh"
#include "BKE_screen.hh"
@@ -55,7 +57,7 @@ void type_popup_unlink(const AssetShelfType &shelf_type)
}
}
static AssetShelf *get_shelf_for_popup(const bContext &C, AssetShelfType &shelf_type)
static AssetShelf *lookup_shelf_for_popup(const bContext &C, const AssetShelfType &shelf_type)
{
Vector<AssetShelf *> &popup_shelves = StaticPopupShelves::shelves();
@@ -68,6 +70,17 @@ static AssetShelf *get_shelf_for_popup(const bContext &C, AssetShelfType &shelf_
}
}
return nullptr;
}
static AssetShelf *get_shelf_for_popup(const bContext &C, AssetShelfType &shelf_type)
{
Vector<AssetShelf *> &popup_shelves = StaticPopupShelves::shelves();
if (AssetShelf *shelf = lookup_shelf_for_popup(C, shelf_type)) {
return shelf;
}
if (type_poll_for_popup(C, &shelf_type)) {
AssetShelf *new_shelf = create_shelf_from_type(shelf_type);
new_shelf->settings.display_flag |= ASSETSHELF_SHOW_NAMES;
@@ -80,6 +93,17 @@ static AssetShelf *get_shelf_for_popup(const bContext &C, AssetShelfType &shelf_
return nullptr;
}
void ensure_asset_library_fetched(const bContext &C, const AssetShelfType &shelf_type)
{
if (AssetShelf *shelf = lookup_shelf_for_popup(C, shelf_type)) {
list::storage_fetch(&shelf->settings.asset_library_reference, &C);
}
else {
AssetLibraryReference library_ref = asset_system::all_library_reference();
list::storage_fetch(&library_ref, &C);
}
}
class AssetCatalogTreeView : public ui::AbstractTreeView {
AssetShelf &shelf_;
asset_system::AssetCatalogTree catalog_tree_;

View File

@@ -53,6 +53,8 @@ void template_asset_shelf_popover(uiLayout &layout,
uiLayoutSetUnitsX(row, name.is_empty() ? 1.6f : 7);
}
ed::asset::shelf::ensure_asset_library_fetched(C, *shelf_type);
uiItemPopoverPanel(row, &C, "ASSETSHELF_PT_popover_panel", name.c_str(), icon);
uiBut *but = static_cast<uiBut *>(block->buttons.last);
if (use_preview_icon) {