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
This commit is contained in:
parent
75af3165ca
commit
c645da98d8
Notes:
blender-bot
2023-02-14 10:04:50 +01:00
Referenced by issue #83050, Dragging a sub-collection out of a scene-linked collection into the "Scene Collection" crashes reliably Referenced by issue #82439, Moving collections between scenes crashes Blender
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue