From 9df91654dc979e3d334de69eded7f816bef223e3 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 16 May 2022 15:37:07 +0200 Subject: Fix T98136: Crash undoing "Make Library Override" in some cases. The 'OVERRIDE_HIDDEN' extra collection would often be mistakenly added to a linked collection, which is totally forbidden and guaranteed to crash on undo/redo. Reworked the code instantiating that extra collection in a more generic and hopefully robust way now. --- source/blender/blenkernel/intern/lib_override.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c index 9dc64365f0c..67df6b5527e 100644 --- a/source/blender/blenkernel/intern/lib_override.c +++ b/source/blender/blenkernel/intern/lib_override.c @@ -1105,8 +1105,8 @@ static void lib_override_library_create_post_process(Main *bmain, if (ID_REAL_USERS(ob_new) != 0) { continue; } - default_instantiating_collection = BKE_collection_add( - bmain, (Collection *)id_root, "OVERRIDE_HIDDEN"); + default_instantiating_collection = BKE_id_new(bmain, ID_GR, "OVERRIDE_HIDDEN"); + id_us_min(&default_instantiating_collection->id); /* Hide the collection from viewport and render. */ default_instantiating_collection->flag |= COLLECTION_HIDE_VIEWPORT | COLLECTION_HIDE_RENDER; @@ -1140,6 +1140,20 @@ static void lib_override_library_create_post_process(Main *bmain, } } + if (id_root != NULL && !ELEM(default_instantiating_collection, NULL, scene->master_collection)) { + ID *id_ref = id_root->newid != NULL ? id_root->newid : id_root; + switch (GS(id_ref->name)) { + case ID_GR: + BKE_collection_add_from_collection( + bmain, scene, (Collection *)id_ref, default_instantiating_collection); + break; + default: + /* Add to master collection. */ + BKE_collection_add_from_collection(bmain, scene, NULL, default_instantiating_collection); + break; + } + } + BLI_gset_free(all_objects_in_scene, NULL); } -- cgit v1.2.3