Fix T63220: Cannot make object single user after Duplicate Scene with Link Object...
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 2 Apr 2019 19:50:17 +0000 (21:50 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 2 Apr 2019 19:53:20 +0000 (21:53 +0200)
Caused by own recent rB17c15798c35f33e (already a fix in that code).

We cannot erase immediately master_collection's childrn list, as it is
used in sub-code to check in how many scenes an object is instanciated.
Further more, we only want to do the remove old/add new children
collections in case we are actually duplicating them.

Makes me even more eager to nuke that whole piece of code and rethink
from scratch that kind of ID handling. Some day...

source/blender/editors/object/object_relations.c

index ec6c105..d069772 100644 (file)
@@ -1627,16 +1627,18 @@ static Collection *single_object_users_collection(
         * However, this means its children need to be re-added manually here, otherwise their parent lists are empty
         * (which will lead to crashes, see T63101). */
        CollectionChild *child_next, *child = collection->children.first;
-       if (is_master_collection) {
-               BLI_listbase_clear(&collection->children);
-       }
-       for (; child; child = child_next) {
+       CollectionChild *orig_child_last = collection->children.last;
+       for (; child != NULL; child = child_next) {
                child_next = child->next;
                Collection *collection_child_new = single_object_users_collection(
                                                       bmain, scene, child->collection, flag, copy_collections, false);
-               if (is_master_collection) {
+               if (is_master_collection && copy_collections && child->collection != collection_child_new) {
                        BKE_collection_child_add(bmain, collection, collection_child_new);
+                       BLI_remlink(&collection->children, child);
                        MEM_freeN(child);
+                       if (child == orig_child_last) {
+                               break;
+                       }
                }
        }