Fix for bug #5666:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 11 Jan 2007 15:00:17 +0000 (15:00 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 11 Jan 2007 15:00:17 +0000 (15:00 +0000)
Crash texture painting with airbrush and pressure, due to division by
zero and resulting nan's. Cause of this crash found by Andrea, thanks!

source/blender/blenkernel/intern/brush.c

index 13f84246deddf65cee2f3a9e6b64ea2ff989add1..53fdb2ac1158c3797cec1cdb76eba7b68750bead 100644 (file)
@@ -807,7 +807,7 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl
                /* compute brush spacing adapted to brush size, spacing may depend
                   on pressure, so update it */
                brush_apply_pressure(painter, brush, painter->lastpressure);
-               spacing= MAX2(1.0, brush->size)*brush->spacing*0.01f;
+               spacing= MAX2(1.0f, brush->size)*brush->spacing*0.01f;
 
                /* setup starting distance, direction vector and accumulated distance */
                startdistance= painter->accumdistance;
@@ -816,15 +816,15 @@ int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, doubl
                painter->accumdistance += len;
 
                /* do paint op over unpainted distance */
-               while (painter->accumdistance >= spacing) {
+               while ((len > 0.0f) && (painter->accumdistance >= spacing)) {
                        step= spacing - startdistance;
                        paintpos[0]= painter->lastmousepos[0] + dmousepos[0]*step;
                        paintpos[1]= painter->lastmousepos[1] + dmousepos[1]*step;
 
                        t = step/len;
-                       press= (1.0-t)*painter->lastpressure + t*pressure;
+                       press= (1.0f-t)*painter->lastpressure + t*pressure;
                        brush_apply_pressure(painter, brush, press);
-                       spacing= MAX2(1.0, brush->size)*brush->spacing*0.01f;
+                       spacing= MAX2(1.0f, brush->size)*brush->spacing*0.01f;
 
                        if (painter->cache.enabled)
                                brush_painter_refresh_cache(painter, paintpos);