RNA Bugfix:
authorJoshua Leung <aligorith@gmail.com>
Sun, 8 May 2011 05:18:40 +0000 (05:18 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sun, 8 May 2011 05:18:40 +0000 (05:18 +0000)
The following script would fail:
#ob = bpy.context.active_object
pb = bpy.context.active_pose_bone
pb.bone.driver_add("hide")  # <--- exception here

The RNA-path function for Bone assumed that when it got called, it's
"id_data" (or owner-idblock-pointer) would only be ID_AR (i.e. an
armature). However, in the above example, pb.bone has ob as its
id_data, resulting in an invalid RNA path getting created. Added check
for this case, since it's likely to be common

source/blender/makesrna/intern/rna_armature.c

index 1b07b224f87335aff2e784c04161c0aeaf5988b9..d398bb4bb787f9aeec66288b2215284a1d5f32d7 100644 (file)
@@ -149,7 +149,20 @@ static void rna_Armature_redraw_data(Main *bmain, Scene *scene, PointerRNA *ptr)
 
 static char *rna_Bone_path(PointerRNA *ptr)
 {
-       return BLI_sprintfN("bones[\"%s\"]", ((Bone*)ptr->data)->name);
+       Bone *bone = (Bone*)ptr->data;
+       
+       /* special exception for trying to get the path where ID-block is Object
+        *      - this will be assumed to be from a Pose Bone...
+        */
+       if (ptr->id.data) {
+               ID *id = (ID *)ptr->id.data;
+               
+               if (GS(id->name) == ID_OB)
+                       return BLI_sprintfN("pose.bones[\"%s\"].bone", bone->name);
+       }
+       
+       /* from armature... */
+       return BLI_sprintfN("bones[\"%s\"]", bone->name);
 }
 
 static IDProperty *rna_Bone_idprops(PointerRNA *ptr, int create)