From 09c32a15d2f9171c2b61220c6ba5cc585f541cb2 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 11 Jun 2019 21:13:37 +0200 Subject: Fix T64430: Removing objects from sub-collection doesn't update instances of parent collection. Collections are a tad annoying with all their caching of objects... When we modify content of a children collection, we need to tag DeG for CoW update of all of the ancestors. For now keeping that recursive tagging helper private, but would not be surprised if we found more similar cases and needed to expose it to more code... --- source/blender/blenkernel/intern/collection.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 03bae118f0f..88ec4f8793f 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -624,6 +624,26 @@ bool BKE_collection_is_empty(Collection *collection) /********************** Collection Objects *********************/ +static void collection_tag_update_parent_recursive(Main *bmain, + Collection *collection, + const int flag) +{ + if (collection->flag & COLLECTION_IS_MASTER) { + return; + } + + DEG_id_tag_update_ex(bmain, &collection->id, flag); + + for (CollectionParent *collection_parent = collection->parents.first; collection_parent; + collection_parent = collection_parent->next) { + if (collection_parent->collection->flag & COLLECTION_IS_MASTER) { + /* We don't care about scene/master collection here. */ + continue; + } + collection_tag_update_parent_recursive(bmain, collection_parent->collection, flag); + } +} + static bool collection_object_add( Main *bmain, Collection *collection, Object *ob, int flag, const bool add_us) { @@ -649,7 +669,7 @@ static bool collection_object_add( } if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) { - DEG_id_tag_update_ex(bmain, &collection->id, ID_RECALC_COPY_ON_WRITE); + collection_tag_update_parent_recursive(bmain, collection, ID_RECALC_COPY_ON_WRITE); } if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) { @@ -679,7 +699,7 @@ static bool collection_object_remove(Main *bmain, id_us_min(&ob->id); } - DEG_id_tag_update_ex(bmain, &collection->id, ID_RECALC_COPY_ON_WRITE); + collection_tag_update_parent_recursive(bmain, collection, ID_RECALC_COPY_ON_WRITE); return true; } -- cgit v1.2.3