[Bf-blender-cvs] [316d2c15220] blender-v2.82-release: Fix T73336: Several issues (including crashes) with ID pointer IDProps and RNA.

Bastien Montagne noreply at git.blender.org
Fri Jan 24 11:40:16 CET 2020


Commit: 316d2c15220d35a9b74b15f940c45ce8d8a09288
Author: Bastien Montagne
Date:   Fri Jan 24 11:26:44 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rB316d2c15220d35a9b74b15f940c45ce8d8a09288

Fix T73336: Several issues (including crashes) with ID pointer IDProps and RNA.

`RNA_property_pointer_set()` was just broken when assigning to an ID
pointer IDProp, on both debug/checks and actual assignment.

That was at least affecting RNA copying and liboverrides area...

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

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

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

diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index d8889455ac7..bd2e522c4b4 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -3762,25 +3762,59 @@ void RNA_property_pointer_set(PointerRNA *ptr,
                               ReportList *reports)
 {
   PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
+  IDProperty *idprop = rna_idproperty_check(&prop, ptr);
   BLI_assert(RNA_property_type(prop) == PROP_POINTER);
 
-  /* Check types */
-  if (ptr_value.type != NULL && !RNA_struct_is_a(ptr_value.type, pprop->type)) {
-    BKE_reportf(reports,
-                RPT_ERROR,
-                "%s: expected %s type, not %s.\n",
-                __func__,
-                pprop->type->identifier,
-                ptr_value.type->identifier);
-    return;
+  /* Check types. */
+  if (pprop->set != NULL) {
+    /* Assigning to a real RNA property. */
+    if (ptr_value.type != NULL && !RNA_struct_is_a(ptr_value.type, pprop->type)) {
+      BKE_reportf(reports,
+                  RPT_ERROR,
+                  "%s: expected %s type, not %s.\n",
+                  __func__,
+                  pprop->type->identifier,
+                  ptr_value.type->identifier);
+      return;
+    }
+  }
+  else {
+    /* Assigning to an IDProperty desguised as RNA one. */
+    if (ptr_value.type != NULL && !RNA_struct_is_a(ptr_value.type, &RNA_ID)) {
+      BKE_reportf(reports,
+                  RPT_ERROR,
+                  "%s: expected ID type, not %s.\n",
+                  __func__,
+                  ptr_value.type->identifier);
+      return;
+    }
   }
 
-  /* RNA */
-  if (pprop->set && !((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
-      !((prop->flag & PROP_ID_SELF_CHECK) && ptr->owner_id == ptr_value.owner_id)) {
+  /* We got an existing IDProperty. */
+  if (idprop != NULL) {
+    /* Not-yet-defined ID IDProps have an IDP_GROUP type, not an IDP_ID one - because of reasons?
+     * XXX This has to be investigated fully - there might be a good reason for it, but off hands
+     * this seems really weird... */
+    if (idprop->type == IDP_ID) {
+      IDP_AssignID(idprop, ptr_value.data, 0);
+      rna_idproperty_touch(idprop);
+    }
+    else {
+      BLI_assert(idprop->type == IDP_GROUP);
+
+      IDPropertyTemplate val = {.id = ptr_value.data};
+      IDProperty *group = RNA_struct_idprops(ptr, true);
+      BLI_assert(group != NULL);
+
+      IDP_ReplaceInGroup_ex(group, IDP_New(IDP_ID, &val, idprop->name), idprop);
+    }
+  }
+  /* RNA property. */
+  else if (pprop->set && !((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
+           !((prop->flag & PROP_ID_SELF_CHECK) && ptr->owner_id == ptr_value.owner_id)) {
     pprop->set(ptr, ptr_value, reports);
   }
-  /* IDProperty */
+  /* IDProperty desguised as RNA property (and not yet defined in ptr). */
   else if (prop->flag & PROP_EDITABLE) {
     IDPropertyTemplate val = {0};
     IDProperty *group;



More information about the Bf-blender-cvs mailing list