From cedfafc9cd97a8bd2f92fcc8bc9c5336cad8dd9d Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 11 Jan 2007 15:00:17 +0000 Subject: [PATCH] Fix for bug #5666: 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 13f84246ded..53fdb2ac115 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -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);