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.
This commit is contained in:
Bastien Montagne 2021-10-06 11:38:11 +02:00
parent b5ea3d2c09
commit 9ed19db539
Notes: blender-bot 2023-02-14 11:21:40 +01:00
Referenced by issue #91969, Library Overrides being duplicated and made local when appending a collection.
2 changed files with 19 additions and 5 deletions

View File

@ -719,7 +719,7 @@ void BKE_libblock_relink_to_newid(ID *id)
static int id_relink_to_newid_looper_new(LibraryIDLinkCallbackData *cb_data)
{
const int cb_flag = cb_data->cb_flag;
if (cb_flag & IDWALK_CB_EMBEDDED) {
if (cb_flag & (IDWALK_CB_EMBEDDED | IDWALK_CB_OVERRIDE_LIBRARY_REFERENCE)) {
return IDWALK_RET_NOP;
}
@ -730,7 +730,11 @@ static int id_relink_to_newid_looper_new(LibraryIDLinkCallbackData *cb_data)
if (id) {
/* See: NEW_ID macro */
if (id->newid != NULL) {
BKE_libblock_relink_ex(bmain, id_owner, id, id->newid, ID_REMAP_SKIP_INDIRECT_USAGE);
BKE_libblock_relink_ex(bmain,
id_owner,
id,
id->newid,
ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_OVERRIDE_LIBRARY);
id = id->newid;
}
if (id->tag & LIB_TAG_NEW) {

View File

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