From: Hector Martin Date: Sat, 18 Dec 2010 19:54:07 +0000 (+0100) Subject: Catch and break out of excessive bezier recursion X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=c03c2f474926c095e31f51706899f73d2bdffbd1;p=openlase.git Catch and break out of excessive bezier recursion --- diff --git a/libol/libol.c b/libol/libol.c index 75f72a7..f95e3be 100644 --- a/libol/libol.c +++ b/libol/libol.c @@ -418,12 +418,17 @@ static void line_to(float x, float y, uint32_t color) dstate.points++; } -static void recurse_bezier(float x1, float y1, float x2, float y2, float x3, float y3, uint32_t color) +static void recurse_bezier(float x1, float y1, float x2, float y2, float x3, float y3, uint32_t color, int depth) { float x0 = dstate.last_point.x; float y0 = dstate.last_point.y; int subdivide = 0; + if (depth > 100) { + olLog("Bezier recurse error: %f,%f %f,%f %f,%f %f,%f\n", x0, y0, x1, y1, x2, y2, x3, y3); + return; + } + float dx = x3-x0; float dy = y3-y0; float distance = fmaxf(fabsf(dx),fabsf(dy)); @@ -456,8 +461,8 @@ static void recurse_bezier(float x1, float y1, float x2, float y2, float x3, flo float by1 = (by2 + mcy) * 0.5; float xm = (ax2 + bx1) * 0.5; float ym = (ay2 + by1) * 0.5; - recurse_bezier(ax1, ay1, ax2, ay2, xm, ym, color); - recurse_bezier(bx1, by1, bx2, by2, x3, y3, color); + recurse_bezier(ax1, ay1, ax2, ay2, xm, ym, color, depth+1); + recurse_bezier(bx1, by1, bx2, by2, x3, y3, color, depth+1); } else { addpoint(x3, y3, color); dstate.last_point = POINT(x3,y3,color); @@ -497,7 +502,7 @@ static void bezier_to(float x, float y, uint32_t color) for (i=0; i