From 60575480583500f27698e2e3e372ec8fab40033e Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 21 Jun 2015 16:06:44 +0200 Subject: Fix/Cleanup possibility to type insane values in 'add' operators options. Our 'hard limit' values was too often max_int/float here, mis-typing could lead to crash (or infinite hanging) of Blender, see e.g. http://blender.stackexchange.com/questions/32790/blender-forces-computer-to-reboot-after-mistyping-extreme-value-for-resolution-i --- source/blender/editors/armature/armature_add.c | 2 +- source/blender/editors/curve/editcurve.c | 15 +++++++----- source/blender/editors/include/ED_object.h | 4 +++ source/blender/editors/mesh/editmesh_add.c | 34 +++++++++++++++----------- source/blender/editors/metaball/mball_edit.c | 5 ++-- source/blender/editors/object/object_add.c | 11 +++++---- 6 files changed, 43 insertions(+), 28 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index e3a69a89a57..59453f0ac71 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -1036,7 +1036,7 @@ void ARMATURE_OT_subdivide(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* Properties */ - prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of Cuts", "", 1, 10); + prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000, "Number of Cuts", "", 1, 10); /* avoid re-using last var because it can cause _very_ high poly meshes and annoy users (or worse crash) */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); } diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 06f0745cc44..1a10814bbf1 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -2527,7 +2527,7 @@ void CURVE_OT_radius_set(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_float(ot->srna, "radius", 1.0f, 0.0f, FLT_MAX, "Radius", "", 0.0001f, 10.0f); + RNA_def_float(ot->srna, "radius", 1.0f, 0.0f, OBJECT_ADD_SIZE_MAXF, "Radius", "", 0.0001f, 10.0f); } /********************* smooth operator ********************/ @@ -3747,7 +3747,7 @@ void CURVE_OT_subdivide(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of cuts", "", 1, 10); + prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000, "Number of cuts", "", 1, 10); /* avoid re-using last var because it can cause _very_ high poly meshes and annoy users (or worse crash) */ RNA_def_property_flag(prop, PROP_SKIP_SAVE); } @@ -4882,8 +4882,9 @@ void CURVE_OT_spin(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_float_vector_xyz(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX); - RNA_def_float_vector(ot->srna, "axis", 3, NULL, -FLT_MAX, FLT_MAX, "Axis", "Axis in global view space", -1.0f, 1.0f); + RNA_def_float_vector_xyz(ot->srna, "center", 3, NULL, -OBJECT_ADD_SIZE_MAXF, OBJECT_ADD_SIZE_MAXF, + "Center", "Center in global view space", -1000.0f, 1000.0f); + RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -1.0f, 1.0f); } /***************** extrude vertex operator **********************/ @@ -5352,7 +5353,8 @@ void CURVE_OT_vertex_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_float_vector_xyz(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Location to add new vertex at", -1e4, 1e4); + RNA_def_float_vector_xyz(ot->srna, "location", 3, NULL, -OBJECT_ADD_SIZE_MAXF, OBJECT_ADD_SIZE_MAXF, + "Location", "Location to add new vertex at", -1.0e4f, 1.0e4f); } /***************** extrude operator **********************/ @@ -6137,7 +6139,8 @@ void CURVE_OT_select_random(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of elements to select randomly", 0.f, 100.0f); + RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, + "Percent", "Percentage of elements to select randomly", 0.0f, 100.0f); WM_operator_properties_select_action_simple(ot, SEL_SELECT); } diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index c52174c8f2d..43f1757a66d 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -131,6 +131,10 @@ float ED_object_new_primitive_matrix( struct bContext *C, struct Object *editob, const float loc[3], const float rot[3], float primmat[4][4]); + +/* Avoid allowing too much insane values even by typing (typos can hang/crash Blender otherwise). */ +#define OBJECT_ADD_SIZE_MAXF 1.0e12f + void ED_object_add_unit_props(struct wmOperatorType *ot); void ED_object_add_generic_props(struct wmOperatorType *ot, bool do_editmode); bool ED_object_add_generic_get_opts(struct bContext *C, struct wmOperator *op, const char view_align_axis, diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c index c67ee41703a..7af6c59adab 100644 --- a/source/blender/editors/mesh/editmesh_add.c +++ b/source/blender/editors/mesh/editmesh_add.c @@ -52,6 +52,10 @@ #include "mesh_intern.h" /* own include */ + +#define MESH_ADD_VERTS_MAXI 10000000 + + /* ********* add primitive operators ************* */ static Object *make_prim_init(bContext *C, const char *idname, @@ -237,7 +241,7 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); + RNA_def_int(ot->srna, "vertices", 32, 3, MESH_ADD_VERTS_MAXI, "Vertices", "", 3, 500); ED_object_add_unit_props(ot); RNA_def_enum(ot->srna, "fill_type", fill_type_items, 0, "Fill Type", ""); @@ -295,9 +299,9 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); + RNA_def_int(ot->srna, "vertices", 32, 3, MESH_ADD_VERTS_MAXI, "Vertices", "", 3, 500); ED_object_add_unit_props(ot); - prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); + prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, OBJECT_ADD_SIZE_MAXF, "Depth", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); RNA_def_enum(ot->srna, "end_fill_type", fill_type_items, 1, "Cap Fill Type", ""); @@ -352,12 +356,12 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500); - prop = RNA_def_float(ot->srna, "radius1", 1.0f, 0.0, FLT_MAX, "Radius 1", "", 0.001, 100.00); + RNA_def_int(ot->srna, "vertices", 32, 3, MESH_ADD_VERTS_MAXI, "Vertices", "", 3, 500); + prop = RNA_def_float(ot->srna, "radius1", 1.0f, 0.0, OBJECT_ADD_SIZE_MAXF, "Radius 1", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); - prop = RNA_def_float(ot->srna, "radius2", 0.0f, 0.0, FLT_MAX, "Radius 2", "", 0.001, 100.00); + prop = RNA_def_float(ot->srna, "radius2", 0.0f, 0.0, OBJECT_ADD_SIZE_MAXF, "Radius 2", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); - prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00); + prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, OBJECT_ADD_SIZE_MAXF, "Depth", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); RNA_def_enum(ot->srna, "end_fill_type", fill_type_items, 1, "Base Fill Type", ""); @@ -408,8 +412,10 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "x_subdivisions", 10, 2, INT_MAX, "X Subdivisions", "", 2, 1000); - RNA_def_int(ot->srna, "y_subdivisions", 10, 2, INT_MAX, "Y Subdivisions", "", 2, 1000); + /* Note that if you use MESH_ADD_VERTS_MAXI for both x and y at the same time you will still reach + * impossible values (10^12 vertices or so...). */ + RNA_def_int(ot->srna, "x_subdivisions", 10, 2, MESH_ADD_VERTS_MAXI, "X Subdivisions", "", 2, 1000); + RNA_def_int(ot->srna, "y_subdivisions", 10, 2, MESH_ADD_VERTS_MAXI, "Y Subdivisions", "", 2, 1000); ED_object_add_unit_props(ot); ED_object_add_generic_props(ot, true); @@ -510,9 +516,9 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "segments", 32, 3, INT_MAX, "Segments", "", 3, 500); - RNA_def_int(ot->srna, "ring_count", 16, 3, INT_MAX, "Rings", "", 3, 500); - prop = RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, 100.00); + RNA_def_int(ot->srna, "segments", 32, 3, MESH_ADD_VERTS_MAXI / 100, "Segments", "", 3, 500); + RNA_def_int(ot->srna, "ring_count", 16, 3, MESH_ADD_VERTS_MAXI / 100, "Rings", "", 3, 500); + prop = RNA_def_float(ot->srna, "size", 1.0f, 0.0, OBJECT_ADD_SIZE_MAXF, "Size", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); ED_object_add_generic_props(ot, true); @@ -563,8 +569,8 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "subdivisions", 2, 1, INT_MAX, "Subdivisions", "", 1, 8); - prop = RNA_def_float(ot->srna, "size", 1.0f, 0.0f, FLT_MAX, "Size", "", 0.001f, 100.00); + RNA_def_int(ot->srna, "subdivisions", 2, 1, 10, "Subdivisions", "", 1, 8); + prop = RNA_def_float(ot->srna, "size", 1.0f, 0.0f, OBJECT_ADD_SIZE_MAXF, "Size", "", 0.001f, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); ED_object_add_generic_props(ot, true); diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index 24cac5b9b70..42eda235276 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -404,7 +404,8 @@ void MBALL_OT_select_random_metaelems(struct wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of elements to select randomly", 0.f, 100.0f); + RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, + "Percent", "Percentage of elements to select randomly", 0.0f, 100.0f); WM_operator_properties_select_action_simple(ot, SEL_SELECT); } @@ -532,7 +533,7 @@ void MBALL_OT_hide_metaelems(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* props */ - RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected"); + RNA_def_boolean(ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected"); } /***************************** Unhide operator *****************************/ diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index b8c66fdd109..075e382f628 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -263,7 +263,7 @@ void ED_object_add_unit_props(wmOperatorType *ot) { PropertyRNA *prop; - prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00); + prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, OBJECT_ADD_SIZE_MAXF, "Radius", "", 0.001, 100.00); RNA_def_property_subtype(prop, PROP_DISTANCE); } @@ -281,11 +281,12 @@ void ED_object_add_generic_props(wmOperatorType *ot, bool do_editmode) RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } - prop = RNA_def_float_vector_xyz(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", - "Location for the newly added object", -FLT_MAX, FLT_MAX); + prop = RNA_def_float_vector_xyz(ot->srna, "location", 3, NULL, -OBJECT_ADD_SIZE_MAXF, OBJECT_ADD_SIZE_MAXF, + "Location", "Location for the newly added object", -1000.0f, 1000.0f); RNA_def_property_flag(prop, PROP_SKIP_SAVE); - prop = RNA_def_float_rotation(ot->srna, "rotation", 3, NULL, -FLT_MAX, FLT_MAX, "Rotation", - "Rotation for the newly added object", (float)-M_PI * 2.0f, (float)M_PI * 2.0f); + prop = RNA_def_float_rotation(ot->srna, "rotation", 3, NULL, -OBJECT_ADD_SIZE_MAXF, OBJECT_ADD_SIZE_MAXF, + "Rotation", "Rotation for the newly added object", + DEG2RADF(-360.0f), DEG2RADF(360.0f)); RNA_def_property_flag(prop, PROP_SKIP_SAVE); prop = RNA_def_boolean_layer_member(ot->srna, "layers", 20, NULL, "Layer", ""); -- cgit v1.2.3