[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55916] trunk/blender/source/blender/ editors: Pressing Ctrl+R when blender was built without bullet would crash.

Campbell Barton ideasman42 at gmail.com
Tue Apr 9 02:57:48 CEST 2013


Revision: 55916
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55916
Author:   campbellbarton
Date:     2013-04-09 00:57:47 +0000 (Tue, 09 Apr 2013)
Log Message:
-----------
Pressing Ctrl+R when blender was built without bullet would crash.
- add checks so rigid-body operators only return FINISHED when they make some changes to the scene.
- remove (scene == NULL) checks, poll already catches these.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_physics.h
    trunk/blender/source/blender/editors/physics/rigidbody_object.c

Modified: trunk/blender/source/blender/editors/include/ED_physics.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_physics.h	2013-04-09 00:46:49 UTC (rev 55915)
+++ trunk/blender/source/blender/editors/include/ED_physics.h	2013-04-09 00:57:47 UTC (rev 55916)
@@ -45,7 +45,7 @@
 int PE_poll_view3d(struct bContext *C);
 
 /* rigidbody_object.c */
-void ED_rigidbody_ob_add(struct wmOperator *op, struct Scene *scene, struct Object *ob, int type);
+bool ED_rigidbody_ob_add(struct wmOperator *op, struct Scene *scene, struct Object *ob, int type);
 void ED_rigidbody_ob_remove(struct Scene *scene, struct Object *ob);
 
 /* rigidbody_constraint.c */

Modified: trunk/blender/source/blender/editors/physics/rigidbody_object.c
===================================================================
--- trunk/blender/source/blender/editors/physics/rigidbody_object.c	2013-04-09 00:46:49 UTC (rev 55915)
+++ trunk/blender/source/blender/editors/physics/rigidbody_object.c	2013-04-09 00:57:47 UTC (rev 55916)
@@ -91,22 +91,26 @@
 
 /* ----------------- */
 
-void ED_rigidbody_ob_add(wmOperator *op, Scene *scene, Object *ob, int type)
+bool ED_rigidbody_ob_add(wmOperator *op, Scene *scene, Object *ob, int type)
 {
 	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
 
 	if (ob->type != OB_MESH) {
 		BKE_report(op->reports, RPT_ERROR, "Can't add Rigid Body to non mesh object");
-		return;
+		return false;
 	}
 	if (((Mesh *)ob->data)->totpoly == 0) {
 		BKE_report(op->reports, RPT_ERROR, "Can't create Rigid Body from mesh with no polygons");
-		return;
+		return false;
 	}
 
 	/* Add rigid body world and group if they don't exist for convenience */
 	if (rbw == NULL) {
 		rbw = BKE_rigidbody_create_world(scene);
+		if (rbw == NULL) {
+			BKE_report(op->reports, RPT_ERROR, "Can't create Rigid Body world");
+			return false;
+		}
 		BKE_rigidbody_validate_sim_world(scene, rbw, false);
 		scene->rigidbody_world = rbw;
 	}
@@ -125,6 +129,8 @@
 	BKE_group_object_add(rbw->group, ob, scene, NULL);
 
 	DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+
+	return true;
 }
 
 void ED_rigidbody_ob_remove(Scene *scene, Object *ob)
@@ -146,17 +152,23 @@
 static int rigidbody_ob_add_exec(bContext *C, wmOperator *op)
 {
 	Scene *scene = CTX_data_scene(C);
-	Object *ob = (scene) ? OBACT : NULL;
+	Object *ob = CTX_data_active_object(C);
 	int type = RNA_enum_get(op->ptr, "type");
+	bool change;
 
 	/* apply to active object */
-	ED_rigidbody_ob_add(op, scene, ob, type);
+	change = ED_rigidbody_ob_add(op, scene, ob, type);
 
-	/* send updates */
-	WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+	if (change) {
+		/* send updates */
+		WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
 
-	/* done */
-	return OPERATOR_FINISHED;
+		/* done */
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
 }
 
 void RIGIDBODY_OT_object_add(wmOperatorType *ot)
@@ -182,25 +194,26 @@
 static int rigidbody_ob_remove_exec(bContext *C, wmOperator *op)
 {
 	Scene *scene = CTX_data_scene(C);
-	Object *ob = (scene) ? OBACT : NULL;
+	Object *ob = CTX_data_active_object(C);
+	bool change = false;
 
-	/* sanity checks */
-	if (scene == NULL)
-		return OPERATOR_CANCELLED;
+	/* apply to active object */
+	if (!ELEM(NULL, ob, ob->rigidbody_object)) {
+		ED_rigidbody_ob_remove(scene, ob);
+		change = true;
+	}
 
-	/* apply to active object */
-	if (ELEM(NULL, ob, ob->rigidbody_object)) {
+	if (change) {
+		/* send updates */
+		WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+
+		/* done */
+		return OPERATOR_FINISHED;
+	}
+	else {
 		BKE_report(op->reports, RPT_ERROR, "Object has no Rigid Body settings to remove");
 		return OPERATOR_CANCELLED;
 	}
-	else
-		ED_rigidbody_ob_remove(scene, ob);
-
-	/* send updates */
-	WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
-
-	/* done */
-	return OPERATOR_FINISHED;
 }
 
 void RIGIDBODY_OT_object_remove(wmOperatorType *ot)
@@ -227,24 +240,25 @@
 {
 	Scene *scene = CTX_data_scene(C);
 	int type = RNA_enum_get(op->ptr, "type");
+	bool change = false;
 
-	/* sanity check */
-	if (scene == NULL) {
-		BKE_report(op->reports, RPT_ERROR, "No Scene to add Rigid Bodies to");
-		return OPERATOR_CANCELLED;
-	}
 	/* create rigid body objects and add them to the world's group */
 	CTX_DATA_BEGIN(C, Object *, ob, selected_objects) {
-		ED_rigidbody_ob_add(op, scene, ob, type);
+		change |= ED_rigidbody_ob_add(op, scene, ob, type);
 	}
 	CTX_DATA_END;
 
-	/* send updates */
-	WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
-	WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
+	if (change) {
+		/* send updates */
+		WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+		WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
 
-	/* done */
-	return OPERATOR_FINISHED;
+		/* done */
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
 }
 
 void RIGIDBODY_OT_objects_add(wmOperatorType *ot)
@@ -270,25 +284,28 @@
 static int rigidbody_obs_remove_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Scene *scene = CTX_data_scene(C);
+	bool change = false;
 
-	/* sanity checks */
-	if (scene == NULL)
-		return OPERATOR_CANCELLED;
-
 	/* apply this to all selected objects... */
 	CTX_DATA_BEGIN(C, Object *, ob, selected_objects)
 	{
 		if (ob->rigidbody_object) {
 			ED_rigidbody_ob_remove(scene, ob);
+			change = true;
 		}
 	}
 	CTX_DATA_END;
 
-	/* send updates */
-	WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
+	if (change) {
+		/* send updates */
+		WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
 
-	/* done */
-	return OPERATOR_FINISHED;
+		/* done */
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
 }
 
 void RIGIDBODY_OT_objects_remove(wmOperatorType *ot)
@@ -313,13 +330,9 @@
 
 static int rigidbody_obs_shape_change_exec(bContext *C, wmOperator *op)
 {
-	Scene *scene = CTX_data_scene(C);
 	int shape = RNA_enum_get(op->ptr, "type");
+	bool change = false;
 
-	/* sanity checks */
-	if (scene == NULL)
-		return OPERATOR_CANCELLED;
-
 	/* apply this to all selected objects... */
 	CTX_DATA_BEGIN(C, Object *, ob, selected_objects)
 	{
@@ -331,15 +344,22 @@
 			RNA_enum_set(&ptr, "collision_shape", shape);
 
 			DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+
+			change = true;
 		}
 	}
 	CTX_DATA_END;
 
-	/* send updates */
-	WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
+	if (change) {
+		/* send updates */
+		WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
 
-	/* done */
-	return OPERATOR_FINISHED;
+		/* done */
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
 }
 
 void RIGIDBODY_OT_shape_change(wmOperatorType *ot)
@@ -539,14 +559,10 @@
 
 static int rigidbody_obs_calc_mass_exec(bContext *C, wmOperator *op)
 {
-	Scene *scene = CTX_data_scene(C);
 	int material = RNA_enum_get(op->ptr, "material");
 	float density;
+	bool change = false;
 
-	/* sanity checks */
-	if (scene == NULL)
-		return OPERATOR_CANCELLED;
-
 	/* get density (kg/m^3) to apply */
 	if (material >= 0) {
 		/* get density from table, and store in props for later repeating */
@@ -581,15 +597,22 @@
 			RNA_float_set(&ptr, "mass", mass);
 
 			DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+
+			change = true;
 		}
 	}
 	CTX_DATA_END;
 
-	/* send updates */
-	WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
+	if (change) {
+		/* send updates */
+		WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL);
 
-	/* done */
-	return OPERATOR_FINISHED;
+		/* done */
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
 }
 
 void RIGIDBODY_OT_mass_calculate(wmOperatorType *ot)




More information about the Bf-blender-cvs mailing list