[Bf-blender-cvs] [31bcab0ecb2] master: Fix (unreported) LibOverride: re-creation of overrides in consecutive partial overrides of a same hierarchy.

Bastien Montagne noreply at git.blender.org
Tue Mar 29 11:22:27 CEST 2022


Commit: 31bcab0ecb2d1de74996bf1cc4bdec3eb78540c5
Author: Bastien Montagne
Date:   Tue Mar 29 11:16:18 2022 +0200
Branches: master
https://developer.blender.org/rB31bcab0ecb2d1de74996bf1cc4bdec3eb78540c5

Fix (unreported) LibOverride: re-creation of overrides in consecutive partial overrides of a same hierarchy.

If creating partial hierarchy overrides (from the outliner e.g.), that
need to create extra overrides, those could be re-created everytime,
leading to very bad situation where there would be several overrides of
the same reference ID in the same override hierarchy.

This fix makes it so that existing overrides in a given hierarchy will
always be re-used in case other overrides are added to the hierarchy.

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

M	source/blender/blenkernel/intern/lib_override.c

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

diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 64ebb08f5d0..cd5855af043 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -322,6 +322,18 @@ ID *BKE_lib_override_library_create_from_id(Main *bmain,
   return local_id;
 }
 
+static void lib_override_prefill_newid_from_existing_overrides(Main *bmain, ID *id_hierarchy_root)
+{
+  ID *id_iter;
+  FOREACH_MAIN_ID_BEGIN (bmain, id_iter) {
+    if (ID_IS_OVERRIDE_LIBRARY_REAL(id_iter) &&
+        id_iter->override_library->hierarchy_root == id_hierarchy_root) {
+      id_iter->override_library->reference->newid = id_iter;
+    }
+  }
+  FOREACH_MAIN_ID_END;
+}
+
 /* TODO: Make this static local function instead? API is becoming complex, and it's not used
  * outside of this file anyway. */
 bool BKE_lib_override_library_create_from_tag(Main *bmain,
@@ -345,6 +357,13 @@ bool BKE_lib_override_library_create_from_tag(Main *bmain,
      * resync process mainly). */
     BLI_assert((ID_IS_OVERRIDE_LIBRARY_REAL(id_hierarchy_root) &&
                 id_hierarchy_root->override_library->reference->lib == id_root_reference->lib));
+
+    if (!do_no_main) {
+      /* When processing within Main, set existing overrides in given hierarchy as 'newid' of their
+       * linked reference. This allows to re-use existing overrides instead of creating new ones in
+       * partial override cases. */
+      lib_override_prefill_newid_from_existing_overrides(bmain, id_hierarchy_root);
+    }
   }
   if (!ELEM(id_hierarchy_root_reference, NULL, id_root_reference)) {
     /* If the reference hierarchy root is given, it must be from the same library as the reference



More information about the Bf-blender-cvs mailing list