[Bf-blender-cvs] [c645da98d87] blender-v2.91-release: Fix T82439: Crash moving collections between scenes

Hans Goudey noreply at git.blender.org
Mon Nov 16 16:59:58 CET 2020


Commit: c645da98d8727e636c14383f4c10706c6cc5ead2
Author: Hans Goudey
Date:   Mon Nov 16 10:59:49 2020 -0500
Branches: blender-v2.91-release
https://developer.blender.org/rBc645da98d8727e636c14383f4c10706c6cc5ead2

Fix T82439: Crash moving collections between scenes

The original code for viewlayer collection flag syncing across moves
from D9158 didn't consider the case where the collection could no longer
be found in its original view layer (moving a collections betwen scenes).

The fix is to just check if the collection starts in the same scene as
it will be moved to before trying to do the flag syncing. I thought about
this for a while and tried a couple other solutions, but I couldn't come
up with a proper way to support syncing the layer collection flags across
scenes without making too many changes.

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

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

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

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

diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 0ed6f94ce79..e6620ea10dc 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -1689,15 +1689,23 @@ bool BKE_collection_move(Main *bmain,
   }
 
   /* Make sure we store the flag of the layer collections before we remove and re-create them.
-   * Otherwise they will get lost and everything will be copied from the new parent collection. */
+   * Otherwise they will get lost and everything will be copied from the new parent collection.
+   * Don't use flag syncing when moving a collection to a different scene, as it no longer exists
+   * in the same view layers anyway. */
+  const bool do_flag_sync = BKE_scene_find_from_collection(bmain, to_parent) ==
+                            BKE_scene_find_from_collection(bmain, collection);
   ListBase layer_flags;
-  layer_collection_flags_store(bmain, collection, &layer_flags);
+  if (do_flag_sync) {
+    layer_collection_flags_store(bmain, collection, &layer_flags);
+  }
 
   /* Create and remove layer collections. */
   BKE_main_collection_sync(bmain);
 
   /* Restore the original layer collection flags. */
-  layer_collection_flags_restore(&layer_flags, collection);
+  if (do_flag_sync) {
+    layer_collection_flags_restore(&layer_flags, collection);
+  }
 
   /* We need to sync it again to pass the correct flags to the collections objects. */
   BKE_main_collection_sync(bmain);



More information about the Bf-blender-cvs mailing list