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

Cyclic check was not checking for collections instanciated by objects...
This commit is contained in:
Bastien Montagne 2020-06-15 17:23:58 +02:00
parent 89bde99674
commit eaff606f2d
Notes: blender-bot 2023-02-14 05:52:32 +01:00
Referenced by issue #77894, Collection Instance Crash
Referenced by issue #77460, Simple scene created in version 2.82 crashes Blender
Referenced by issue #77348, Blender LTS: Maintenance Task 2.83
1 changed files with 23 additions and 1 deletions

View File

@ -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)