From 9ed19db5392d76bc810afabeb93fcd34a23fd88d Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 6 Oct 2021 11:38:11 +0200 Subject: Fix handling of overrides during append. Liboverride references need a special handling during append, since those pointers should never be made local, nor reampped to newly localized data. And liboverride references should never be directly made local either, to ensure their liboverride usages remain pointing to linked data and not local one. Issue was reported by the studio, and also probably as part of T91892. --- source/blender/windowmanager/intern/wm_files_link.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_files_link.c') diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index cf3536213d2..12ab10e3a70 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -595,7 +595,10 @@ static void wm_append_loose_data_instantiate(WMLinkAppendData *lapp_data, static int foreach_libblock_append_callback(LibraryIDLinkCallbackData *cb_data) { - if (cb_data->cb_flag & (IDWALK_CB_EMBEDDED | IDWALK_CB_INTERNAL | IDWALK_CB_LOOPBACK)) { + /* NOTE: It is important to also skip liboverride references here, as those should never be made + * local. */ + if (cb_data->cb_flag & (IDWALK_CB_EMBEDDED | IDWALK_CB_INTERNAL | IDWALK_CB_LOOPBACK | + IDWALK_CB_OVERRIDE_LIBRARY_REFERENCE)) { return IDWALK_RET_NOP; } @@ -652,7 +655,8 @@ static void wm_append_do(WMLinkAppendData *lapp_data, LinkNode *itemlink; - /* Generate a mapping between newly linked IDs and their items. */ + /* Generate a mapping between newly linked IDs and their items, and tag linked IDs used as + * liboverride references as already existing. */ lapp_data->new_id_to_item = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); for (itemlink = lapp_data->items.list; itemlink; itemlink = itemlink->next) { WMLinkAppendDataItem *item = itemlink->link; @@ -661,6 +665,13 @@ static void wm_append_do(WMLinkAppendData *lapp_data, continue; } BLI_ghash_insert(lapp_data->new_id_to_item, id, item); + + /* This ensures that if a liboverride reference is also linked/used by some other appended + * data, it gets a local copy instead of being made directly local, so that the liboverride + * references remain valid (i.e. linked data). */ + if (ID_IS_OVERRIDE_LIBRARY_REAL(id)) { + id->override_library->reference->tag |= LIB_TAG_PRE_EXISTING; + } } lapp_data->library_weak_reference_mapping = BKE_main_library_weak_reference_create(bmain); @@ -704,7 +715,6 @@ static void wm_append_do(WMLinkAppendData *lapp_data, item->append_action = WM_APPEND_ACT_COPY_LOCAL; } else { - /* In future we could search for already existing matching local ID etc. */ CLOG_INFO(&LOG, 3, "Appended ID '%s' will be made local...", id->name); item->append_action = WM_APPEND_ACT_MAKE_LOCAL; } -- cgit v1.2.3