From f48556f236b707b9f5f319d72ac630dc718ce1e3 Mon Sep 17 00:00:00 2001 From: Matt Ebb Date: Tue, 29 Jun 2010 12:33:25 +0000 Subject: [PATCH] Fix [#22355] Spin Tool crashes Blender on Click'n'Drag Steps Spin tool steps property had no softmin/softmax (set to INT_MAX), and without continuous grab on, the number field dragging code would jump up to ridiculously high numbers. Added a reasonable soft max for spin, and also added some protection to the button dragging code to prevent the drag increments from getting too high. Probably need to doublecheck other op property softmaxes as well. --- .../editors/interface/interface_handlers.c | 18 ++++++++++-------- source/blender/editors/mesh/editmesh_tools.c | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 1f9c2bb9ce0..eda7102e69b 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -24,6 +24,7 @@ */ #include +#include #include #include #include @@ -2223,7 +2224,6 @@ static int ui_numedit_but_NUM(uiBut *but, uiHandleButtonData *data, float fac, i softmax= but->softmax; softrange= softmax - softmin; - if(ui_is_a_warp_but(but)) { /* Mouse location isn't screen clamped to the screen so use a linear mapping * 2px == 1-int, or 1px == 1-ClickStep */ @@ -2283,15 +2283,18 @@ static int ui_numedit_but_NUM(uiBut *but, uiHandleButtonData *data, float fac, i /* Use a non-linear mapping of the mouse drag especially for large floats (normal behavior) */ deler= 500; if(!ui_is_but_float(but)) { - if((softrange)<100) deler= 200.0; - if((softrange)<25) deler= 50.0; + /* prevent large ranges from getting too out of control */ + if (softrange > 600) deler = powf(softrange, 0.75); + + if (softrange < 100) deler= 200.0; + if (softrange < 25) deler= 50.0; } deler /= fac; - if(ui_is_but_float(but) && softrange > 11) { + if(softrange > 11) { /* non linear change in mouse input- good for high precicsion */ data->dragf+= (((float)(mx-data->draglastx))/deler) * (fabs(data->dragstartx-mx)*0.002); - } else if (!ui_is_but_float(but) && softrange > 129) { /* only scale large int buttons */ + } else if (softrange > 129) { /* only scale large int buttons */ /* non linear change in mouse input- good for high precicsionm ints need less fine tuning */ data->dragf+= (((float)(mx-data->draglastx))/deler) * (fabs(data->dragstartx-mx)*0.004); } else { @@ -2299,8 +2302,7 @@ static int ui_numedit_but_NUM(uiBut *but, uiHandleButtonData *data, float fac, i data->dragf+= ((float)(mx-data->draglastx))/deler ; } - if(data->dragf>1.0) data->dragf= 1.0; - if(data->dragf<0.0) data->dragf= 0.0; + CLAMP(data->dragf, 0.0, 1.0); data->draglastx= mx; tempf= (softmin + data->dragf*softrange); @@ -2312,7 +2314,7 @@ static int ui_numedit_but_NUM(uiBut *but, uiHandleButtonData *data, float fac, i CLAMP(temp, softmin, softmax); lvalue= (int)data->value; - + if(temp != lvalue) { data->dragchange= 1; data->value= (double)temp; diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 13656ca1b7e..a46d154cc22 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -1030,7 +1030,7 @@ void MESH_OT_spin(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* props */ - RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX); + RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 128); RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates"); RNA_def_float(ot->srna, "degrees", 90.0f, -FLT_MAX, FLT_MAX, "Degrees", "Degrees", -360.0f, 360.0f);