Fix T57816: Crash when deleting recently orphaned collection
authorDalai Felinto <dfelinto@gmail.com>
Tue, 18 Dec 2018 22:36:57 +0000 (20:36 -0200)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 21 Dec 2018 09:49:10 +0000 (07:49 -0200)
We were never removing the parent collection from a collection upon removal
of the parent.

Reviewers: mont29

Differential Revision: https://developer.blender.org/D4099

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

index 33287d5..a3782de 100644 (file)
@@ -683,8 +683,9 @@ static void collection_missing_parents_remove(Collection *collection)
 {
        for (CollectionParent *parent = collection->parents.first, *parent_next; parent != NULL; parent = parent_next) {
                parent_next = parent->next;
-
-               if (!collection_find_child(parent->collection, collection)) {
+               if ((parent->collection == NULL) ||
+                   !collection_find_child(parent->collection, collection))
+               {
                        BLI_freelinkN(&collection->parents, parent);
                }
        }
index 9428e15..ab50cf8 100644 (file)
@@ -747,6 +747,9 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
                                for (CollectionChild *child = collection->children.first; child; child = child->next) {
                                        CALLBACK_INVOKE(child->collection, IDWALK_CB_USER);
                                }
+                               for (CollectionParent *parent = collection->parents.first; parent; parent = parent->next) {
+                                       CALLBACK_INVOKE(parent->collection, IDWALK_CB_NOP);
+                               }
                                break;
                        }