Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2022-06-01 13:44:11 +0300
committerBastien Montagne <bastien@blender.org>2022-06-01 16:04:34 +0300
commite72b86d3cba8c7366bee2e92162f3b07bf367f3d (patch)
treee93ed98e072576085dbc58d918551aa93cf86571 /source/blender/blenkernel/intern/object.cc
parent7dd0258d4a439335fd69a4f0d1716a67c926ffe8 (diff)
Fix T98469: Crash trying to add an object to a linked collection that is linked to multiple scenes.
Crash happened because code could not find a valid base in current scene after adding the object, added some checks for that. Root of the issue was wrong assumptions in `BKE_object_add` logic, which would pick the first valid ancestor collection in case initially selected collection was not editable. In some case, this could pick a collection not instanced in the current scene's view layer, leading to not getting a valid base for the newly added object. Addressed this by adding a new variant of `BKE_collection_object_add`, `BKE_collection_viewlayer_object_add`, which ensures final collection is in given viewlayer.
Diffstat (limited to 'source/blender/blenkernel/intern/object.cc')
-rw-r--r--source/blender/blenkernel/intern/object.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 2a25d73ed87..0bc092bec4f 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -2271,10 +2271,14 @@ Object *BKE_object_add(Main *bmain, ViewLayer *view_layer, int type, const char
Object *ob = object_add_common(bmain, view_layer, type, name);
LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
- BKE_collection_object_add(bmain, layer_collection->collection, ob);
+ BKE_collection_viewlayer_object_add(bmain, view_layer, layer_collection->collection, ob);
+ /* Note: There is no way to be sure that #BKE_collection_viewlayer_object_add will actually
+ * manage to find a valid collection in given `view_layer` to add the new object to. */
Base *base = BKE_view_layer_base_find(view_layer, ob);
- BKE_view_layer_base_select_and_set_active(view_layer, base);
+ if (base != nullptr) {
+ BKE_view_layer_base_select_and_set_active(view_layer, base);
+ }
return ob;
}