[Bf-blender-cvs] [fe0a65512ff] temp-outliner-library-override-hierarchy: Correct logic to avoid IDs recursing into themselves

Julian Eisel noreply at git.blender.org
Fri Mar 25 18:49:13 CET 2022


Commit: fe0a65512ffcaddc9c59406ea8ee5b13d9958086
Author: Julian Eisel
Date:   Fri Mar 25 16:29:43 2022 +0100
Branches: temp-outliner-library-override-hierarchy
https://developer.blender.org/rBfe0a65512ffcaddc9c59406ea8ee5b13d9958086

Correct logic to avoid IDs recursing into themselves

===================================================================

M	source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchy.cc

===================================================================

diff --git a/source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchy.cc b/source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchy.cc
index 186c7c3b6fb..b7b8206b214 100644
--- a/source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchy.cc
+++ b/source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchy.cc
@@ -167,14 +167,6 @@ static int build_hierarchy_foreach_ID_cb(LibraryIDLinkCallbackData *cb_data)
   if (real_override_id->override_library->hierarchy_root != &build_data.override_root_id) {
     return IDWALK_RET_NOP;
   }
-  /* ID was added already, don't add it again to avoid (endless) recursion. We might want to still
-   * add an element for this but don't recurse further into it, to show that this ID is used
-   * multiple times in the hierarchy. */
-  /* TODO is this correct? Shouldn't we only check if the ID is one of the ancestors, not anywhere
-   * in the hierarchy? */
-  if (build_data.added_elems.contains(&id)) {
-    return IDWALK_RET_STOP_RECURSION;
-  }
 
   TreeElement *te_to_expand = &build_data.root_id_te.getLegacyElement();
   /* If there is already an element for the ID linking to the current one, use that as parent. */
@@ -183,6 +175,17 @@ static int build_hierarchy_foreach_ID_cb(LibraryIDLinkCallbackData *cb_data)
     te_to_expand = parent_te_id;
   }
 
+  /* Check if an ancestor of this element is already the ID we want to add, this would mean an ID
+   * recurses into itself. Don't add the element and stop recursing in that case. */
+  for (TreeElement *parent_iter_te = te_to_expand; parent_iter_te;
+       parent_iter_te = parent_iter_te->parent) {
+    if (TreeElementID *id_te = tree_element_cast<TreeElementID>(parent_iter_te)) {
+      if (&id_te->get_ID() == &id) {
+        return IDWALK_RET_STOP_RECURSION;
+      }
+    }
+  }
+
   TreeElement *new_te = outliner_add_element(
       &build_data.space_outliner, &te_to_expand->subtree, &id, te_to_expand, TSE_SOME_ID, 0);
   remove_expanded_children(*new_te);



More information about the Bf-blender-cvs mailing list