[Bf-blender-cvs] [676beae23ef] override-refactor-tmp: LibOverrides: First stage of detection of 'need resync'.

Bastien Montagne noreply at git.blender.org
Thu Dec 31 18:06:44 CET 2020


Commit: 676beae23ef73d7c77998de54fa4d70a7804f63c
Author: Bastien Montagne
Date:   Thu Dec 31 18:03:45 2020 +0100
Branches: override-refactor-tmp
https://developer.blender.org/rB676beae23ef73d7c77998de54fa4d70a7804f63c

LibOverrides: First stage of detection of 'need resync'.

We can fairly easily detect some resync-needed cases when applying the
overrides operations on a Pointer RNA property.

This should cover all cases where an existing override's ID pointer is
changed in its linked data.

We still have to add code to detect when a not-yet-overridden linked ID
needs to become overridden (because its relations to other data-blocks
changed in a way that requires it).

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

M	source/blender/blenkernel/intern/lib_override.c
M	source/blender/makesdna/DNA_ID.h
M	source/blender/makesrna/intern/rna_access_compare_override.c

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

diff --git a/source/blender/blenkernel/intern/lib_override.c b/source/blender/blenkernel/intern/lib_override.c
index 6ae3c313508..64fd8ff61c9 100644
--- a/source/blender/blenkernel/intern/lib_override.c
+++ b/source/blender/blenkernel/intern/lib_override.c
@@ -817,6 +817,8 @@ bool BKE_lib_override_library_resync(Main *bmain, Scene *scene, ViewLayer *view_
         ID *id_override_new = id->newid;
         ID *id_override_old = BLI_ghash_lookup(linkedref_to_old_override, id);
 
+        BLI_assert((id_override_new->flag & LIB_LIB_OVERRIDE_NEED_RESYNC) == 0);
+
         if (id_override_old != NULL) {
           /* Swap the names between old override ID and new one. */
           char id_name_buf[MAX_ID_NAME];
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 287e47c70f3..568673e1fed 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -555,6 +555,10 @@ enum {
    * Note that this also applies to shapekeys, even though they are not 100% embedded data...
    */
   LIB_EMBEDDED_DATA_LIB_OVERRIDE = 1 << 12,
+  /**
+   * The data-block is a library override that needs re-sync to its linked reference.
+   */
+  LIB_LIB_OVERRIDE_NEED_RESYNC = 1 << 13,
 };
 
 /**
diff --git a/source/blender/makesrna/intern/rna_access_compare_override.c b/source/blender/makesrna/intern/rna_access_compare_override.c
index 1e7f5e841ba..119ca07606f 100644
--- a/source/blender/makesrna/intern/rna_access_compare_override.c
+++ b/source/blender/makesrna/intern/rna_access_compare_override.c
@@ -56,7 +56,7 @@
  * Find the actual ID owner of the given \a ptr #PointerRNA, in override sense, and generate the
  * full rna path from it to given \a prop #PropertyRNA if \a rna_path is given.
  *
- * \note this is slightly different than 'generic' RNA 'id owner' as returned by
+ * \note This is slightly different than 'generic' RNA 'id owner' as returned by
  * #RNA_find_real_ID_and_path, since in overrides we also consider shape keys as embedded data, not
  * only root node trees and master collections.
  */
@@ -99,10 +99,6 @@ static ID *rna_property_override_property_real_id_owner(Main *bmain,
     }
   }
 
-  if (!ID_IS_OVERRIDE_LIBRARY_REAL(owner_id)) {
-    return NULL;
-  }
-
   if (r_rna_path == NULL) {
     return owner_id;
   }
@@ -1152,6 +1148,41 @@ void RNA_struct_override_apply(Main *bmain,
               ptr_storage, op->rna_path, &data_storage, &prop_storage, &data_item_storage);
         }
 
+        /* Check if an overridden ID pointer supposed to be in sync with linked data gets out of
+         * sync. */
+        if ((ptr_dst->owner_id->flag & LIB_LIB_OVERRIDE_NEED_RESYNC) == 0 &&
+            op->rna_prop_type == PROP_POINTER &&
+            (((IDOverrideLibraryPropertyOperation *)op->operations.first)->flag &
+             IDOVERRIDE_LIBRARY_FLAG_IDPOINTER_MATCH_REFERENCE) != 0) {
+          BLI_assert(ptr_src->owner_id ==
+                     rna_property_override_property_real_id_owner(bmain, &data_src, NULL, NULL));
+          BLI_assert(ptr_dst->owner_id ==
+                     rna_property_override_property_real_id_owner(bmain, &data_dst, NULL, NULL));
+
+          ID *id_src = RNA_property_pointer_get(&data_src, prop_src).owner_id;
+          ID *id_dst = RNA_property_pointer_get(&data_dst, prop_dst).owner_id;
+
+          PointerRNA prop_ptr_src, prop_ptr_dst;
+          RNA_id_pointer_create(id_src, &prop_ptr_src);
+          RNA_id_pointer_create(id_dst, &prop_ptr_dst);
+
+          id_src = rna_property_override_property_real_id_owner(bmain, &prop_ptr_src, NULL, NULL);
+          id_dst = rna_property_override_property_real_id_owner(bmain, &prop_ptr_dst, NULL, NULL);
+
+          BLI_assert(id_src == NULL || ID_IS_OVERRIDE_LIBRARY_REAL(id_src));
+
+          if (/* We might be in a case where id_dst has already been processed and its usages
+               * remapped to its new local override. In that case overrides and linked data are
+               * always properly matching. */
+              id_src != id_dst &&
+              /* If one of the pointers is NULL and not the other, or if linked reference ID of
+               * `id_src` is not `id_dst`,  we are in a non-matching case. */
+              (ELEM(NULL, id_src, id_dst) || id_src->override_library->reference != id_dst)) {
+            ptr_dst->owner_id->flag |= LIB_LIB_OVERRIDE_NEED_RESYNC;
+            printf("Local override %s detected as needing resync!\n", ptr_dst->owner_id->name);
+          }
+        }
+
         rna_property_override_apply_ex(bmain,
                                        &data_dst,
                                        &data_src,



More information about the Bf-blender-cvs mailing list