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.
This commit is contained in:
Bastien Montagne 2022-05-16 15:37:07 +02:00
parent 48754bc146
commit 9df91654dc
Notes: blender-bot 2023-02-14 00:44:02 +01:00
Referenced by issue #98136, Crash undoing "Make Library Override" for linked collection with shapekey
1 changed files with 16 additions and 2 deletions

View File

@ -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);
}