[Bf-blender-cvs] [9ed19db5392] master: Fix handling of overrides during append.

Bastien Montagne noreply at git.blender.org
Wed Oct 6 11:56:38 CEST 2021


Commit: 9ed19db5392d76bc810afabeb93fcd34a23fd88d
Author: Bastien Montagne
Date:   Wed Oct 6 11:38:11 2021 +0200
Branches: master
https://developer.blender.org/rB9ed19db5392d76bc810afabeb93fcd34a23fd88d

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.

===================================================================

M	source/blender/blenkernel/intern/lib_remap.c
M	source/blender/windowmanager/intern/wm_files_link.c

===================================================================

diff --git a/source/blender/blenkernel/intern/lib_remap.c b/source/blender/blenkernel/intern/lib_remap.c
index 48396c5e6d9..b5c45c0902b 100644
--- a/source/blender/blenkernel/intern/lib_remap.c
+++ b/source/blender/blenkernel/intern/lib_remap.c
@@ -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) {
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;
     }



More information about the Bf-blender-cvs mailing list