[Bf-blender-cvs] [1c106e189aa] master: RNA: fix the id_data pointer of PoseBone.bone to point at the Armature.

Alexander Gavrilov noreply at git.blender.org
Tue May 14 11:41:27 CEST 2019


Commit: 1c106e189aafe235ca5e83c97ce477c80ccc437a
Author: Alexander Gavrilov
Date:   Tue May 14 12:38:04 2019 +0300
Branches: master
https://developer.blender.org/rB1c106e189aafe235ca5e83c97ce477c80ccc437a

RNA: fix the id_data pointer of PoseBone.bone to point at the Armature.

The owning ID reference of RNA pointers is supposed to point at the
ID container that owns the object, but for PoseBone.bone it wasn't
updated to point at the Armature data ID instead of Armature Object.

This caused issues, like pose_bone.bone.driver_add() adding the
driver to the Armature Object animation data, which violates the
intended design of the animation data structures.

Since RNA code generally assumes that all pointers that don't
refer directly to an ID remain within the current ID, a custom
getter is required to fix this.

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

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

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

diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index 7babbbdc8c7..2f7f8c70760 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -289,6 +289,18 @@ static void rna_PoseChannel_name_set(PointerRNA *ptr, const char *value)
   ED_armature_bone_rename(G_MAIN, ob->data, oldname, newname);
 }
 
+static PointerRNA rna_PoseChannel_bone_get(PointerRNA *ptr)
+{
+  Object *ob = (Object *)ptr->id.data;
+  bPoseChannel *pchan = (bPoseChannel *)ptr->data;
+  PointerRNA tmp_ptr = *ptr;
+
+  /* Replace the id_data pointer with the Armature ID. */
+  tmp_ptr.id.data = ob->data;
+
+  return rna_pointer_inherit_refine(&tmp_ptr, &RNA_Bone, pchan->bone);
+}
+
 static bool rna_PoseChannel_has_ik_get(PointerRNA *ptr)
 {
   Object *ob = (Object *)ptr->id.data;
@@ -916,6 +928,7 @@ static void rna_def_pose_channel(BlenderRNA *brna)
   prop = RNA_def_property(srna, "bone", PROP_POINTER, PROP_NONE);
   RNA_def_property_flag(prop, PROP_NEVER_NULL);
   RNA_def_property_struct_type(prop, "Bone");
+  RNA_def_property_pointer_funcs(prop, "rna_PoseChannel_bone_get", NULL, NULL, NULL);
   RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(prop, "Bone", "Bone associated with this PoseBone");



More information about the Bf-blender-cvs mailing list