[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28588] trunk/blender/source/blender/ editors/object/object_constraint.c: Bugfix #22244: Crash on using ops. constraint.childof_set_inverse and childOf_clear_inverse incorrectly

Joshua Leung aligorith at gmail.com
Wed May 5 02:44:42 CEST 2010


Revision: 28588
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28588
Author:   aligorith
Date:     2010-05-05 02:44:42 +0200 (Wed, 05 May 2010)

Log Message:
-----------
Bugfix #22244: Crash on using ops.constraint.childof_set_inverse and childOf_clear_inverse incorrectly

Adding some NULL checks to all the constraint operators. This is not ideal, but at least the crashes are gone now. More work is needed to properly fix this...

Modified Paths:
--------------
    trunk/blender/source/blender/editors/object/object_constraint.c

Modified: trunk/blender/source/blender/editors/object/object_constraint.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_constraint.c	2010-05-05 00:28:16 UTC (rev 28587)
+++ trunk/blender/source/blender/editors/object/object_constraint.c	2010-05-05 00:44:42 UTC (rev 28588)
@@ -527,8 +527,12 @@
 {
 	Object *ob = ED_object_active_context(C);
 	bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_STRETCHTO);
-	bStretchToConstraint *data= (bStretchToConstraint *)con->data;
-
+	bStretchToConstraint *data= (con) ? (bStretchToConstraint *)con->data : NULL;
+	
+	/* despite 3 layers of checks, we may still not be able to find a constraint */
+	if (data == NULL)
+		return OPERATOR_CANCELLED;
+	
 	/* just set original length to 0.0, which will cause a reset on next recalc */
 	data->orglength = 0.0f;
 	ED_object_constraint_update(ob);
@@ -566,8 +570,12 @@
 {
 	Object *ob = ED_object_active_context(C);
 	bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_DISTLIMIT);
-	bDistLimitConstraint *data= (bDistLimitConstraint *)con->data;
+	bDistLimitConstraint *data= (con) ? (bDistLimitConstraint *)con->data : NULL;
 	
+	/* despite 3 layers of checks, we may still not be able to find a constraint */
+	if (data == NULL)
+		return OPERATOR_CANCELLED;
+	
 	/* just set original length to 0.0, which will cause a reset on next recalc */
 	data->dist = 0.0f;
 	ED_object_constraint_update(ob);
@@ -601,22 +609,19 @@
 }
 
 /* ------------- Child-Of Constraint ------------------ */
-#if 0 // unused
-static int childof_poll(bContext *C)
-{
-	PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_ChildOfConstraint);
-	return (ptr.id.data && ptr.data);
-}
-#endif
 /* ChildOf Constraint - set inverse callback */
 static int childof_set_inverse_exec (bContext *C, wmOperator *op)
 {
 	Scene *scene= CTX_data_scene(C);
 	Object *ob = ED_object_active_context(C);
 	bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_CHILDOF);
-	bChildOfConstraint *data= (bChildOfConstraint *)con->data;
+	bChildOfConstraint *data= (con) ? (bChildOfConstraint *)con->data : NULL;
 	bPoseChannel *pchan= NULL;
-
+	
+	/* despite 3 layers of checks, we may still not be able to find a constraint */
+	if (data == NULL)
+		return OPERATOR_CANCELLED;
+	
 	/* try to find a pose channel */
 	// TODO: get from context instead?
 	if (ob && ob->pose)
@@ -694,7 +699,7 @@
 {
 	Object *ob = ED_object_active_context(C);
 	bConstraint *con = edit_constraint_property_get(C, op, ob, CONSTRAINT_TYPE_CHILDOF);
-	bChildOfConstraint *data= (bChildOfConstraint *)con->data;
+	bChildOfConstraint *data= (con) ? (bChildOfConstraint *)con->data : NULL;
 	
 	/* simply clear the matrix */
 	unit_m4(data->invmat);





More information about the Bf-blender-cvs mailing list