From dc78e47b770b33645f3cda1a4750422cd5105d6b Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Sat, 7 May 2016 23:40:59 +1200 Subject: [PATCH] Fix for D1705: Update to fix the bug with extra triangles that produces glitches in some situations --- source/blender/editors/gpencil/drawgpencil.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index a2ddbca9213..6ccbd2777b4 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -389,7 +389,7 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps) gp_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction); BLI_polyfill_calc((const float(*)[2])points2d, (unsigned int)gps->totpoints, direction, (unsigned int(*)[3])tmp_triangles); - /* count number of valid triangles */ + /* count number of valid triangles, slower but safer */ gps->tot_triangles = 0; for (int i = 0; i < gps->totpoints; i++) { if ((tmp_triangles[i][0] >= 0) && (tmp_triangles[i][0] < gps->totpoints) && @@ -399,6 +399,11 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps) gps->tot_triangles++; } } + + if (gps->tot_triangles > gps->totpoints - 2) { + /* avoid problems with extra (unwanted) triangles getting created */ + gps->tot_triangles = gps->totpoints - 2; + } //printf("tot triangles: %d / %d - direction = %d\n", gps->tot_triangles, gps->totpoints, direction); /* save triangulation data in stroke cache */