From 91d2d547031366bd19ac6806a01355820dab1c2a Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 24 Sep 2025 11:57:02 +0200 Subject: [PATCH] Fix Outliner File view not grouping indirectly linked libraries. Indirectly linked libraries are supposed to be put under their 'best parent' library, this has been broken in the outliner for some times. for several reasons. This commit addresses the 'outliner hierarchy building' part of the problem. The 'everything ends up directly linked' is addressed by !146667. Pull Request: https://projects.blender.org/blender/blender/pulls/146669 --- .../tree/tree_display_libraries.cc | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/source/blender/editors/space_outliner/tree/tree_display_libraries.cc b/source/blender/editors/space_outliner/tree/tree_display_libraries.cc index a1f5b610e4d..ff90f065789 100644 --- a/source/blender/editors/space_outliner/tree/tree_display_libraries.cc +++ b/source/blender/editors/space_outliner/tree/tree_display_libraries.cc @@ -57,8 +57,12 @@ ListBase TreeDisplayLibraries::build_tree(const TreeSourceData &source_data) } } - /* make hierarchy */ - for (TreeElement *ten : List(tree)) { + /* Make hierarchy. + * + * Note: `List` template is similar to `LISTBASE_FOREACH`, _not_ `LISTBASE_FOREACH_MUTABLE`, + * so we need to iterate over an actual copy of the original list here, to avoid missing some + * items. */ + for (TreeElement *ten : listbase_to_vector(tree)) { if (ten == tree.first) { /* First item is main, skip. */ continue; @@ -71,21 +75,11 @@ ListBase TreeDisplayLibraries::build_tree(const TreeSourceData &source_data) continue; } - TreeElement *parent = (TreeElement *)lib->runtime->parent->id.newid; - - if (tselem->id->tag & ID_TAG_INDIRECT) { - /* Only remove from 'first level' if lib is not also directly used. */ - BLI_remlink(&tree, ten); - BLI_addtail(&parent->subtree, ten); - ten->parent = parent; - } - else { - /* Else, make a new copy of the libtree for our parent. */ - TreeElement *dupten = add_library_contents(*source_data.bmain, parent->subtree, lib); - if (dupten) { - dupten->parent = parent; - } - } + /* A library with a non-null `parent` is always strictly indirectly linked. */ + TreeElement *parent = reinterpret_cast(lib->runtime->parent->id.newid); + BLI_remlink(&tree, ten); + BLI_addtail(&parent->subtree, ten); + ten->parent = parent; } /* restore newid pointers */ for (ID *library_id : List(source_data.bmain->libraries)) {