[Bf-blender-cvs] [ac723db57fd] blender-v2.82-release: Fix T71798: Full Copy Scene produce Orphan Data objects.

Bastien Montagne noreply at git.blender.org
Tue Jan 14 12:10:34 CET 2020


Commit: ac723db57fd8ba5493088b135ef7c910be4ca2ff
Author: Bastien Montagne
Date:   Tue Jan 14 12:07:24 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rBac723db57fd8ba5493088b135ef7c910be4ca2ff

Fix T71798: Full Copy Scene produce Orphan Data objects.

Never treat one of those horrorible 'IDs that are not real IDs' as
regular ID, and expect ID management code to do so. Unless there is a
very good reason, one should never explicitely pass those fake IDs to ID
management code directly.

In that specific case, user count is sort of 'disabled' in libquery
code, because master collections are not in bmain (`LIB_TAG_NO_MAIN`).

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

M	source/blender/editors/object/object_relations.c

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

diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index c030c551374..06d5bd8beb4 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -1706,19 +1706,29 @@ void OBJECT_OT_make_links_data(wmOperatorType *ot)
 
 /**************************** Make Single User ********************************/
 
-static void libblock_relink_collection(Collection *collection)
+static void libblock_relink_collection(Collection *collection, const bool do_collection)
 {
-  BKE_libblock_relink_to_newid(&collection->id);
+  if (do_collection) {
+    BKE_libblock_relink_to_newid(&collection->id);
+  }
 
   for (CollectionObject *cob = collection->gobject.first; cob != NULL; cob = cob->next) {
     BKE_libblock_relink_to_newid(&cob->ob->id);
   }
 
   for (CollectionChild *child = collection->children.first; child; child = child->next) {
-    libblock_relink_collection(child->collection);
+    libblock_relink_collection(child->collection, true);
   }
 }
 
+static void libblock_relink_collections_from_scene(Scene *scene)
+{
+  /* Will also handle the master collection. */
+  BKE_libblock_relink_to_newid(&scene->id);
+
+  libblock_relink_collection(scene->master_collection, false);
+}
+
 static Collection *single_object_users_collection(Main *bmain,
                                                   Scene *scene,
                                                   Collection *collection,
@@ -1807,7 +1817,7 @@ static void single_object_users(
 #endif
 
   /* Collection and object pointers in collections */
-  libblock_relink_collection(master_collection);
+  libblock_relink_collections_from_scene(scene);
 
   /* collection pointers in scene */
   BKE_scene_groups_relink(scene);
@@ -2056,7 +2066,7 @@ void ED_object_single_users(Main *bmain,
      * rewritten at some point to make use of proper modern ID management code,
      * but that is no small task.
      * For now we are doomed to that kind of band-aid to try to cover most of remapping cases. */
-    libblock_relink_collection(scene->master_collection);
+    libblock_relink_collections_from_scene(scene);
   }
 
   /* Relink nodetrees' pointers that have been duplicated. */



More information about the Bf-blender-cvs mailing list