Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2020-06-15 18:23:58 +0300
committerJeroen Bakker <jeroen@blender.org>2020-06-25 10:31:45 +0300
commit293b00beb5df27b4455de743fd0684f0988153b0 (patch)
tree831a9d99167492c5bba7ca239813fd63ef6b4190
parent517f32045c282f1031299268ad0ebfa8f934bd1a (diff)
Fix T77460: Easy to create cyclic dependencies in collections and crash Blender.
Cyclic check was not checking for collections instanciated by objects...
-rw-r--r--source/blender/blenkernel/intern/collection.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 583bb39a851..c1218856a1e 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -969,6 +969,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) {
@@ -981,7 +1001,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)