[Bf-blender-cvs] [eb33ee566e3] master: Fix T: Crash in do-version of older pre-2.80 blender files.

Bastien Montagne noreply at git.blender.org
Fri Jan 14 17:02:09 CET 2022


Commit: eb33ee566e33ec6d4d128e57a8555999adc1bf19
Author: Bastien Montagne
Date:   Fri Jan 14 15:24:43 2022 +0100
Branches: master
https://developer.blender.org/rBeb33ee566e33ec6d4d128e57a8555999adc1bf19

Fix T: Crash in do-version of older pre-2.80 blender files.

`BKE_layer_collection_sync` was missing a specific handling for one of
those pre-master collection cases,

NOTE: It is a bit unfortunate to have to do 'do-version' code in BKE...
At some point might look into moving this into actual `do_version` file,
but this is not fully trivial not critical improvement for now.

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

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

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

diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index c58820b239b..9e3cea40fb8 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -1207,11 +1207,22 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
     return;
   }
 
-  /* In some cases (from older files) we do have a master collection, yet no matching layer. Create
-   * the master one here, so that the rest of the code can work as expected. */
   if (BLI_listbase_is_empty(&view_layer->layer_collections)) {
+    /* In some cases (from older files) we do have a master collection, yet no matching layer.
+     * Create the master one here, so that the rest of the code can work as expected. */
     layer_collection_add(&view_layer->layer_collections, scene->master_collection);
   }
+  else if (BLI_listbase_count_at_most(&view_layer->layer_collections, 2) > 1) {
+    /* In some cases (from older files) we do have a master collection, but no matching layer,
+     * instead all the children of the master collection have their layer collections in the
+     * viewlayer's list. This is not a valid situation, add a layer for the master collection and
+     * add all existing first-level layers as children of that new master layer. */
+    ListBase layer_collections = view_layer->layer_collections;
+    BLI_listbase_clear(&view_layer->layer_collections);
+    LayerCollection *master_layer_collection = layer_collection_add(&view_layer->layer_collections,
+                                                                    scene->master_collection);
+    master_layer_collection->layer_collections = layer_collections;
+  }
 
   /* Free cache. */
   MEM_SAFE_FREE(view_layer->object_bases_array);



More information about the Bf-blender-cvs mailing list