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.
This commit is contained in:
Matt Ebb 2010-06-29 12:33:25 +00:00
parent 3c1e97d1ff
commit f48556f236
2 changed files with 11 additions and 9 deletions

@ -24,6 +24,7 @@
*/
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
@ -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;

@ -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);