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.
This commit is contained in:
Alexander Gavrilov 2019-05-14 12:38:04 +03:00
parent 02e3bf22ab
commit 1c106e189a
1 changed files with 13 additions and 0 deletions

View File

@ -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");