[Bf-blender-cvs] [d8bb429964d] master: Fix T68651: LibOverride: Fix bad handling of RNA collections pointers.

Bastien Montagne noreply at git.blender.org
Fri Aug 16 16:26:04 CEST 2019


Commit: d8bb429964df170d27fe4a89e1c5ef754f0d018a
Author: Bastien Montagne
Date:   Fri Aug 16 16:19:52 2019 +0200
Branches: master
https://developer.blender.org/rBd8bb429964df170d27fe4a89e1c5ef754f0d018a

Fix T68651: LibOverride:  Fix bad handling of RNA collections pointers.

We were storing the 'item' part in the RNA path of the override op
itself, which will not work with IDs because overriding local one might
not have the same name as the linked one (when some local ID with same
name already exists).

Now we are properly handling  this using the expected actual override
operation, which stores necessary data (names or indices) from both
local and linked data.

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

M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_rna.c

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

diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 330d45c2fa5..b78a3304cc7 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -8860,6 +8860,80 @@ static void rna_property_override_apply_ex(Main *bmain,
       }
       continue;
     }
+
+    /* Note: will have to think about putting that logic into its own function maybe?
+     * Would be nice to have it in a single place... */
+    PointerRNA private_ptr_item_local, private_ptr_item_override, private_ptr_item_storage;
+    if (opop->subitem_local_name != NULL || opop->subitem_reference_name != NULL ||
+        opop->subitem_local_index != -1 || opop->subitem_reference_index != -1) {
+      RNA_POINTER_INVALIDATE(&private_ptr_item_local);
+      RNA_POINTER_INVALIDATE(&private_ptr_item_override);
+      RNA_POINTER_INVALIDATE(&private_ptr_item_storage);
+      if (opop->subitem_local_name != NULL) {
+        RNA_property_collection_lookup_string(
+            ptr_local, prop_local, opop->subitem_local_name, &private_ptr_item_local);
+        if (opop->subitem_reference_name != NULL) {
+          RNA_property_collection_lookup_string(ptr_override,
+                                                prop_override,
+                                                opop->subitem_reference_name,
+                                                &private_ptr_item_override);
+        }
+        else {
+          RNA_property_collection_lookup_string(
+              ptr_override, prop_override, opop->subitem_local_name, &private_ptr_item_override);
+        }
+      }
+      else if (opop->subitem_reference_name != NULL) {
+        RNA_property_collection_lookup_string(
+            ptr_local, prop_local, opop->subitem_reference_name, &private_ptr_item_local);
+        RNA_property_collection_lookup_string(
+            ptr_override, prop_override, opop->subitem_reference_name, &private_ptr_item_override);
+      }
+      else if (opop->subitem_local_index != -1) {
+        RNA_property_collection_lookup_int(
+            ptr_local, prop_local, opop->subitem_local_index, &private_ptr_item_local);
+        if (opop->subitem_reference_index != -1) {
+          RNA_property_collection_lookup_int(ptr_override,
+                                             prop_override,
+                                             opop->subitem_reference_index,
+                                             &private_ptr_item_override);
+        }
+        else {
+          RNA_property_collection_lookup_int(
+              ptr_override, prop_override, opop->subitem_local_index, &private_ptr_item_override);
+        }
+      }
+      else if (opop->subitem_reference_index != -1) {
+        RNA_property_collection_lookup_int(
+            ptr_local, prop_local, opop->subitem_reference_index, &private_ptr_item_local);
+        RNA_property_collection_lookup_int(ptr_override,
+                                           prop_override,
+                                           opop->subitem_reference_index,
+                                           &private_ptr_item_override);
+      }
+      if (prop_storage != NULL) {
+        if (opop->subitem_local_name != NULL) {
+          RNA_property_collection_lookup_string(
+              ptr_storage, prop_storage, opop->subitem_local_name, &private_ptr_item_storage);
+        }
+        else if (opop->subitem_reference_name != NULL) {
+          RNA_property_collection_lookup_string(
+              ptr_storage, prop_storage, opop->subitem_reference_name, &private_ptr_item_storage);
+        }
+        else if (opop->subitem_local_index != -1) {
+          RNA_property_collection_lookup_int(
+              ptr_storage, prop_storage, opop->subitem_local_index, &private_ptr_item_storage);
+        }
+        else if (opop->subitem_reference_index != -1) {
+          RNA_property_collection_lookup_int(
+              ptr_storage, prop_storage, opop->subitem_reference_index, &private_ptr_item_storage);
+        }
+      }
+      ptr_item_local = &private_ptr_item_local;
+      ptr_item_override = &private_ptr_item_override;
+      ptr_item_storage = &private_ptr_item_storage;
+    }
+
     if (!rna_property_override_operation_apply(bmain,
                                                ptr_local,
                                                ptr_override,
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index 631ad72e146..cb075884915 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -1241,6 +1241,10 @@ static int rna_property_override_diff_propptr(Main *bmain,
                                               const bool no_prop_name,
                                               IDOverrideLibrary *override,
                                               const char *rna_path,
+                                              const char *rna_itemname_a,
+                                              const char *rna_itemname_b,
+                                              const int rna_itemindex_a,
+                                              const int rna_itemindex_b,
                                               const int flags,
                                               bool *r_override_changed)
 {
@@ -1282,9 +1286,18 @@ static int rna_property_override_diff_propptr(Main *bmain,
         IDOverrideLibraryProperty *op = BKE_override_library_property_get(
             override, rna_path, &created);
 
-        if (op != NULL && created) { /* If not yet overridden... */
-          BKE_override_library_property_operation_get(
-              op, IDOVERRIDE_LIBRARY_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
+        /* If not yet overridden, or if we are handling sub-items (inside a collection)... */
+        if (op != NULL && (created || rna_itemname_a != NULL || rna_itemname_b != NULL ||
+                           rna_itemindex_a != -1 || rna_itemindex_b != -1)) {
+          BKE_override_library_property_operation_get(op,
+                                                      IDOVERRIDE_LIBRARY_OP_REPLACE,
+                                                      rna_itemname_b,
+                                                      rna_itemname_a,
+                                                      rna_itemindex_b,
+                                                      rna_itemindex_a,
+                                                      true,
+                                                      NULL,
+                                                      &created);
           if (r_override_changed) {
             *r_override_changed = created;
           }
@@ -1294,12 +1307,56 @@ static int rna_property_override_diff_propptr(Main *bmain,
       return comp;
     }
     else {
+      /* In case we got some array/collection like items identifiers, now is the time to generate a
+       * proper rna path from those. */
+#  define RNA_PATH_BUFFSIZE 8192
+
+      char extended_rna_path_buffer[RNA_PATH_BUFFSIZE];
+      char *extended_rna_path = extended_rna_path_buffer;
+
+#  define RNA_PATH_PRINTF(_str, ...) \
+    if (BLI_snprintf(extended_rna_path_buffer, RNA_PATH_BUFFSIZE, (_str), __VA_ARGS__) >= \
+        RNA_PATH_BUFFSIZE - 1) { \
+      extended_rna_path = BLI_sprintfN((_str), __VA_ARGS__); \
+    } \
+    (void)0
+#  define RNA_PATH_FREE() \
+    if (extended_rna_path != extended_rna_path_buffer && extended_rna_path != rna_path) \
+    MEM_freeN(extended_rna_path)
+
+      /* There may be a propname defined in some cases, while no actual name set
+       * (e.g. happens with point cache), in that case too we want to fall back to index.
+       * Note that we do not need the RNA path for insertion operations. */
+      if (rna_path) {
+        if ((rna_itemname_a != NULL && rna_itemname_a[0] != '\0') &&
+            (rna_itemname_b != NULL && rna_itemname_b[0] != '\0')) {
+          BLI_assert(STREQ(rna_itemname_a, rna_itemname_b));
+          char esc_item_name[RNA_PATH_BUFFSIZE];
+          BLI_strescape(esc_item_name, rna_itemname_a, RNA_PATH_BUFFSIZE);
+          RNA_PATH_PRINTF("%s[\"%s\"]", rna_path, esc_item_name);
+        }
+        else if (rna_itemindex_a != -1) { /* Based on index... */
+          BLI_assert(rna_itemindex_a == rna_itemindex_b);
+          RNA_PATH_PRINTF("%s[%d]", rna_path, rna_itemindex_a);
+        }
+        else {
+          extended_rna_path = (char *)rna_path;
+        }
+      }
+
       eRNAOverrideMatchResult report_flags = 0;
       const bool match = RNA_struct_override_matches(
-          bmain, propptr_a, propptr_b, rna_path, override, flags, &report_flags);
+          bmain, propptr_a, propptr_b, extended_rna_path, override, flags, &report_flags);
       if (r_override_changed && (report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) != 0) {
         *r_override_changed = true;
       }
+
+      RNA_PATH_FREE();
+
+#  undef RNA_PATH_BUFFSIZE
+#  undef RNA_PATH_PRINTF
+#  undef RNA_PATH_FREE
+
       return !match;
     }
   }
@@ -1616,6 +1673,10 @@ int rna_property_override_diff_default(Main *bmain,
                                                   no_prop_name,
                                                   override,
                                                   rna_path,
+                                                  NULL,
+                                                  NULL,
+                                                  -1,
+                                                  -1,
                                                   flags,
                                                   r_override_changed);
       }
@@ -1636,21 +1697,6 @@ int rna_property_override_diff_default(Main *bmain,
       int idx_a = 0;
       int idx_b = 0;
 
-#  define RNA_PATH_BUFFSIZE 8192
-
-      char extended_rna_path_buffer[RNA_PATH_BUFFSIZE];
-      char *extended_rna_path = extended_rna_path_buffer;
-
-#  define RNA_PATH_PRINTF(_str, ...) \
-    if (BLI_snprintf(extended_rna_path_buffer, RNA_PATH_BUFFSIZE, (_str), __VA_ARGS__) >= \
-        RNA_PATH_BUFFSIZE - 1) { \
-      extended_rna_path = BLI_sprintfN((_st

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list