From a379fce14bdaa9fd9011d6fd0591b50f94773229 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 12 Oct 2022 11:45:25 +0200 Subject: Fix T101679: Duplicate objects are created when 'Make' override is called on existing override in 3DView When the active selected object in the 3DView is already a local liboverride, only perform the 'clear system flag' process on selected objects, there is no point in trying to create an override out of it. --- source/blender/editors/object/object_relations.c | 29 +++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 2f18922f4ee..5da19d76259 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -2318,26 +2318,39 @@ static int make_override_library_exec(bContext *C, wmOperator *op) id_root = &collection->id; user_overrides_from_selected_objects = true; } - /* Else, poll func ensures us that ID_IS_LINKED(obact) is true. */ + /* Else, poll func ensures us that ID_IS_LINKED(obact) is true, or that it is already an existing + * liboverride. */ else { + BLI_assert(ID_IS_LINKED(obact) || ID_IS_OVERRIDE_LIBRARY_REAL(obact)); id_root = &obact->id; user_overrides_from_selected_objects = true; } - const bool do_fully_editable = !user_overrides_from_selected_objects; - - GSet *user_overrides_objects_uids = do_fully_editable ? NULL : - BLI_gset_new(BLI_ghashutil_inthash_p, - BLI_ghashutil_intcmp, - __func__); - /* Make already existing selected liboverrides editable. */ + bool is_active_override = false; FOREACH_SELECTED_OBJECT_BEGIN (view_layer, CTX_wm_view3d(C), ob_iter) { if (ID_IS_OVERRIDE_LIBRARY_REAL(ob_iter) && !ID_IS_LINKED(ob_iter)) { ob_iter->id.override_library->flag &= ~IDOVERRIDE_LIBRARY_FLAG_SYSTEM_DEFINED; + is_active_override = is_active_override || (&ob_iter->id == id_root); + DEG_id_tag_update(&ob_iter->id, ID_RECALC_COPY_ON_WRITE); } } FOREACH_SELECTED_OBJECT_END; + /* If the active object is a liboverride, there is no point going further, since in the weird + * case where some other selected objects would be linked ones, there is no way to properly + * create overrides for them currently. + * + * Could be added later if really needed, but would rather avoid that extra complexity here. */ + if (is_active_override) { + return OPERATOR_FINISHED; + } + + const bool do_fully_editable = !user_overrides_from_selected_objects; + + GSet *user_overrides_objects_uids = do_fully_editable ? NULL : + BLI_gset_new(BLI_ghashutil_inthash_p, + BLI_ghashutil_intcmp, + __func__); if (do_fully_editable) { /* Pass. */ -- cgit v1.2.3