[Bf-blender-cvs] [eaff606f2db] master: Fix T77460: Easy to create cyclic dependencies in collections and crash Blender.

Bastien Montagne noreply at git.blender.org
Mon Jun 15 17:26:01 CEST 2020


Commit: eaff606f2dbbf99b09fac57f4034b70c53a398ef
Author: Bastien Montagne
Date:   Mon Jun 15 17:23:58 2020 +0200
Branches: master
https://developer.blender.org/rBeaff606f2dbbf99b09fac57f4034b70c53a398ef

Fix T77460: Easy to create cyclic dependencies in collections and crash Blender.

Cyclic check was not checking for collections instanciated by objects...

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

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

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index a9d3c7c1b65..1928a6da0fa 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -1070,6 +1070,26 @@ void BKE_collections_after_lib_link(Main *bmain)
 
 /********************** Collection Children *******************/
 
+static bool collection_find_instance_recursive(Collection *collection,
+                                               Collection *instance_collection)
+{
+  LISTBASE_FOREACH (CollectionObject *, collection_object, &collection->gobject) {
+    if (collection_object->ob != NULL &&
+        /* Object from a given collection should never instanciate that collection either. */
+        ELEM(collection_object->ob->instance_collection, instance_collection, collection)) {
+      return true;
+    }
+  }
+
+  LISTBASE_FOREACH (CollectionChild *, collection_child, &collection->children) {
+    if (collection_find_instance_recursive(collection_child->collection, instance_collection)) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 bool BKE_collection_find_cycle(Collection *new_ancestor, Collection *collection)
 {
   if (collection == new_ancestor) {
@@ -1082,7 +1102,9 @@ bool BKE_collection_find_cycle(Collection *new_ancestor, Collection *collection)
     }
   }
 
-  return false;
+  /* Find possible objects in collection or its children, that would instanciate the given ancestor
+   * collection (that would also make a fully invalid cycle of dependencies) .*/
+  return collection_find_instance_recursive(collection, new_ancestor);
 }
 
 static CollectionChild *collection_find_child(Collection *parent, Collection *collection)



More information about the Bf-blender-cvs mailing list