[Bf-blender-cvs] [8366c3ecd8e] blender2.8: Depsgraph: Ensure collections are up to date after modifications

Sergey Sharybin noreply at git.blender.org
Thu Jun 7 14:41:37 CEST 2018


Commit: 8366c3ecd8ea70edab27b17e31df21302c9c366f
Author: Sergey Sharybin
Date:   Thu Jun 7 14:39:58 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB8366c3ecd8ea70edab27b17e31df21302c9c366f

Depsgraph: Ensure collections are up to date after modifications

Before that copied collection in copy-on-write were running out
of sync with original ones. This was causing crash with the
following scenario:

- Delete some objects from scene
- Add particle system to an object
- Change particle mode to Hair

Thanks Dalai for debug session! Pair programming ftw!

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

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

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index aa16c899612..ab0ec8b0491 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -59,7 +59,7 @@
 
 static bool collection_child_add(Collection *parent, Collection *collection, int flag, const bool add_us);
 static bool collection_child_remove(Collection *parent, Collection *collection);
-static bool collection_object_add(Collection *collection, Object *ob, int flag, const bool add_us);
+static bool collection_object_add(Main *bmain, Collection *collection, Object *ob, int flag, const bool add_us);
 static bool collection_object_remove(Main *bmain, Collection *collection, Object *ob, const bool free_us);
 
 static CollectionChild *collection_find_child(Collection *parent, Collection *collection);
@@ -163,7 +163,7 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy)
 			/* Link child object into parent collections. */
 			for (CollectionParent *cparent = collection->parents.first; cparent; cparent = cparent->next) {
 				Collection *parent = cparent->collection;
-				collection_object_add(parent, cob->ob, 0, true);
+				collection_object_add(bmain, parent, cob->ob, 0, true);
 			}
 
 			/* Remove child object. */
@@ -190,7 +190,7 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy)
  * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
  */
 void BKE_collection_copy_data(
-        Main *UNUSED(bmain), Collection *collection_dst, const Collection *collection_src, const int flag)
+        Main *bmain, Collection *collection_dst, const Collection *collection_src, const int flag)
 {
 	/* Do not copy collection's preview (same behavior as for objects). */
 	if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) {  /* XXX TODO temp hack */
@@ -211,7 +211,7 @@ void BKE_collection_copy_data(
 		collection_child_add(collection_dst, child->collection, flag, false);
 	}
 	for (CollectionObject *cob = collection_src->gobject.first; cob; cob = cob->next) {
-		collection_object_add(collection_dst, cob->ob, flag, false);
+		collection_object_add(bmain, collection_dst, cob->ob, flag, false);
 	}
 }
 
@@ -505,7 +505,7 @@ Collection *BKE_collection_object_find(Main *bmain, Collection *collection, Obje
 
 /********************** Collection Objects *********************/
 
-static bool collection_object_add(Collection *collection, Object *ob, int flag, const bool add_us)
+static bool collection_object_add(Main *bmain, Collection *collection, Object *ob, int flag, const bool add_us)
 {
 	if (ob->dup_group) {
 		/* Cyclic dependency check. */
@@ -528,6 +528,10 @@ static bool collection_object_add(Collection *collection, Object *ob, int flag,
 		id_us_plus(&ob->id);
 	}
 
+	if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) {
+		DEG_id_tag_update_ex(bmain, &collection->id, DEG_TAG_COPY_ON_WRITE);
+	}
+
 	return true;
 }
 
@@ -548,6 +552,8 @@ static bool collection_object_remove(Main *bmain, Collection *collection, Object
 		id_us_min(&ob->id);
 	}
 
+	DEG_id_tag_update_ex(bmain, &collection->id, DEG_TAG_COPY_ON_WRITE);
+
 	return true;
 }
 
@@ -560,7 +566,7 @@ bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
 		return false;
 	}
 
-	if (!collection_object_add(collection, ob, 0, true)) {
+	if (!collection_object_add(bmain, collection, ob, 0, true)) {
 		return false;
 	}
 
@@ -580,7 +586,7 @@ void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, O
 	FOREACH_SCENE_COLLECTION_BEGIN(scene, collection)
 	{
 		if (BKE_collection_has_object(collection, ob_src)) {
-			collection_object_add(collection, ob_dst, 0, true);
+			collection_object_add(bmain, collection, ob_dst, 0, true);
 		}
 	}
 	FOREACH_SCENE_COLLECTION_END;



More information about the Bf-blender-cvs mailing list