[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56206] trunk/blender/source/blender: Bugfix [#34836] Crash when driver variable has path == 'data'

Joshua Leung aligorith at gmail.com
Mon Apr 22 15:22:09 CEST 2013


Revision: 56206
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56206
Author:   aligorith
Date:     2013-04-22 13:22:07 +0000 (Mon, 22 Apr 2013)
Log Message:
-----------
Bugfix [#34836] Crash when driver variable has path == 'data'

Most of the places which relied on RNA_path_resolve() did so believing that if
it returned true, that it had found a valid property, and that the returned
pointer+property combination would be what the path referred to. However, it
turns out that if the property at the end of the path turns out to be a
"pointer" property (e.g. "data" for Object.data), this would automatically
become the pointer part, while the prop part would be set to null. Hence, if a
user accidentally (or otherwise) specifies a path for the single-property driver
variable type like this, then Blender would crash.

This commit introduces two convenience functions - RNA_path_resolve_property()
and RNA_path_resolve_property_full() - which mirror/wrap the existing
RNA_path_resolve() functions. The only difference though is that these include a
check to ensure that what was found from resolving the path was in fact a
property (they only return true iff this is the case), and make it explicitly
clear in the name that this is what they will do so that there's no further
confusion. It is possible to do without these wrapper functions by doing these
checks inline, but the few cases that had been patched already were pretty
hideous looking specimens. Using these just make it clearer and simpler for all.

I've also beefed up the docs on these a bit, and changed these to using bools.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/anim_sys.c
    trunk/blender/source/blender/blenkernel/intern/fcurve.c
    trunk/blender/source/blender/editors/animation/anim_channels_defines.c
    trunk/blender/source/blender/editors/animation/anim_deps.c
    trunk/blender/source/blender/editors/animation/anim_draw.c
    trunk/blender/source/blender/editors/animation/anim_ipo_utils.c
    trunk/blender/source/blender/editors/animation/drivers.c
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/editors/animation/keyingsets.c
    trunk/blender/source/blender/editors/armature/pose_slide.c
    trunk/blender/source/blender/editors/interface/interface_ops.c
    trunk/blender/source/blender/editors/space_graph/graph_buttons.c
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/python/intern/bpy_rna_anim.c

Modified: trunk/blender/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -550,7 +550,7 @@
 /* Path Validation -------------------------------------------- */
 
 /* Check if a given RNA Path is valid, by tracing it from the given ID, and seeing if we can resolve it */
-static short check_rna_path_is_valid(ID *owner_id, const char *path)
+static bool check_rna_path_is_valid(ID *owner_id, const char *path)
 {
 	PointerRNA id_ptr, ptr;
 	PropertyRNA *prop = NULL;
@@ -559,7 +559,7 @@
 	RNA_id_pointer_create(owner_id, &id_ptr);
 	
 	/* try to resolve */
-	return RNA_path_resolve(&id_ptr, path, &ptr, &prop); 
+	return RNA_path_resolve_property(&id_ptr, path, &ptr, &prop); 
 }
 
 /* Check if some given RNA Path needs fixing - free the given path and set a new one as appropriate 
@@ -1164,7 +1164,7 @@
 	//printf("%p %s %i %f\n", ptr, path, array_index, value);
 	
 	/* get property to write to */
-	if (RNA_path_resolve(ptr, path, &new_ptr, &prop)) {
+	if (RNA_path_resolve_property(ptr, path, &new_ptr, &prop)) {
 		/* set value - only for animatable numerical values */
 		if (RNA_property_animateable(&new_ptr, prop)) {
 			int array_len = RNA_property_array_length(&new_ptr, prop);
@@ -1650,7 +1650,7 @@
 	/* free_path = */ /* UNUSED */ animsys_remap_path(strip->remap, fcu->rna_path, &path);
 	
 	/* a valid property must be available, and it must be animatable */
-	if (RNA_path_resolve(ptr, path, &new_ptr, &prop) == 0) {
+	if (RNA_path_resolve_property(ptr, path, &new_ptr, &prop) == false) {
 		if (G.debug & G_DEBUG) printf("NLA Strip Eval: Cannot resolve path\n");
 		return NULL;
 	}

Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -1040,7 +1040,7 @@
 	RNA_id_pointer_create(id, &id_ptr);
 	
 	/* get property to read from, and get value as appropriate */
-	if (RNA_path_resolve_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) {
+	if (RNA_path_resolve_property_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) {
 		if (RNA_property_array_check(prop)) {
 			/* array */
 			if ((index >= 0) && (index < RNA_property_array_length(&ptr, prop))) {

Modified: trunk/blender/source/blender/editors/animation/anim_channels_defines.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/editors/animation/anim_channels_defines.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -3280,7 +3280,7 @@
 	RNA_id_pointer_create(id, &id_ptr);
 	
 	/* try to resolve the path stored in the F-Curve */
-	if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) {
+	if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) {
 		/* set the special 'replace' flag if on a keyframe */
 		if (fcurve_frame_has_keyframe(fcu, cfra, 0))
 			flag |= INSERTKEY_REPLACE;
@@ -3318,7 +3318,7 @@
 	RNA_id_pointer_create((ID *)key, &id_ptr);
 	
 	/* try to resolve the path stored in the F-Curve */
-	if (RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop)) {
+	if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) {
 		/* find or create new F-Curve */
 		// XXX is the group name for this ok?
 		bAction *act = verify_adt_action((ID *)key, 1);
@@ -3615,7 +3615,7 @@
 					RNA_id_pointer_create(ale->id, &id_ptr);
 					
 					/* try to resolve the path */
-					if (RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop)) {
+					if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) {
 						uiBut *but;
 						
 						/* create the slider button, and assign relevant callback to ensure keyframes are inserted... */

Modified: trunk/blender/source/blender/editors/animation/anim_deps.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_deps.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/editors/animation/anim_deps.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -87,7 +87,7 @@
 		
 		RNA_id_pointer_create(id, &id_ptr);
 			
-		if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop))
+		if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop))
 			RNA_property_update_main(G.main, scene, &ptr, prop);
 	}
 	else {

Modified: trunk/blender/source/blender/editors/animation/anim_draw.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_draw.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/editors/animation/anim_draw.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -373,7 +373,7 @@
 		
 		/* get RNA property that F-Curve affects */
 		RNA_id_pointer_create(id, &id_ptr);
-		if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) {
+		if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) {
 			/* rotations: radians <-> degrees? */
 			if (RNA_SUBTYPE_UNIT(RNA_property_subtype(prop)) == PROP_UNIT_ROTATION) {
 				/* if the radians flag is not set, default to using degrees which need conversions */

Modified: trunk/blender/source/blender/editors/animation/anim_ipo_utils.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_ipo_utils.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/editors/animation/anim_ipo_utils.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -79,7 +79,7 @@
 		RNA_id_pointer_create(id, &id_ptr);
 		
 		/* try to resolve the path */
-		if (RNA_path_resolve(&id_ptr, fcu->rna_path, &ptr, &prop)) {
+		if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) {
 			const char *structname = NULL, *propname = NULL;
 			char arrayindbuf[16];
 			const char *arrayname = NULL;

Modified: trunk/blender/source/blender/editors/animation/drivers.c
===================================================================
--- trunk/blender/source/blender/editors/animation/drivers.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/editors/animation/drivers.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -145,7 +145,7 @@
 	
 	/* validate pointer first - exit if failure */
 	RNA_id_pointer_create(id, &id_ptr);
-	if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
+	if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
 		BKE_reportf(reports, RPT_ERROR, 
 		            "Could not add driver, as RNA path is invalid for the given ID (ID = %s, path = %s)",
 		            id->name, rna_path);
@@ -308,7 +308,7 @@
 	
 	/* validate pointer first - exit if failure */
 	RNA_id_pointer_create(id, &id_ptr);
-	if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
+	if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
 		BKE_reportf(reports, RPT_ERROR,
 		            "Could not find driver to copy, as RNA path is invalid for the given ID (ID = %s, path = %s)",
 		            id->name, rna_path);
@@ -355,7 +355,7 @@
 	
 	/* validate pointer first - exit if failure */
 	RNA_id_pointer_create(id, &id_ptr);
-	if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
+	if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
 		BKE_reportf(reports, RPT_ERROR,
 		            "Could not paste driver, as RNA path is invalid for the given ID (ID = %s, path = %s)",
 		            id->name, rna_path);

Modified: trunk/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframing.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/editors/animation/keyframing.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -810,7 +810,7 @@
 		PointerRNA tmp_ptr;
 		
 		/* try to get property we should be affecting */
-		if ((RNA_path_resolve(&ptr, fcu->rna_path, &tmp_ptr, &prop) == 0) || (prop == NULL)) {
+		if (RNA_path_resolve_property(&ptr, fcu->rna_path, &tmp_ptr, &prop) == false) {
 			/* property not found... */
 			const char *idname = (ptr.id.data) ? ((ID *)ptr.id.data)->name : TIP_("<No ID pointer>");
 			
@@ -920,7 +920,7 @@
 	}
 	
 	RNA_id_pointer_create(id, &id_ptr);
-	if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
+	if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
 		BKE_reportf(reports, RPT_ERROR,
 		            "Could not insert keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
 		            (id) ? id->name : TIP_("<Missing ID block>"), rna_path);
@@ -1012,7 +1012,7 @@
 	
 	/* validate pointer first - exit if failure */
 	RNA_id_pointer_create(id, &id_ptr);
-	if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
+	if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
 		BKE_reportf(reports, RPT_ERROR,
 		            "Could not delete keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
 		            id->name, rna_path);
@@ -1113,7 +1113,7 @@
 
 	/* validate pointer first - exit if failure */
 	RNA_id_pointer_create(id, &id_ptr);
-	if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
+	if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop) == false) {
 		BKE_reportf(reports, RPT_ERROR,
 		            "Could not clear keyframe, as RNA path is invalid for the given ID (ID = %s, path = %s)",
 		            id->name, rna_path);

Modified: trunk/blender/source/blender/editors/animation/keyingsets.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyingsets.c	2013-04-22 12:28:54 UTC (rev 56205)
+++ trunk/blender/source/blender/editors/animation/keyingsets.c	2013-04-22 13:22:07 UTC (rev 56206)
@@ -977,7 +977,7 @@
 			PropertyRNA *prop;
 			
 			RNA_id_pointer_create(ksp->id, &id_ptr);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list