Commit: 6855ba4034158b916122b1d881b3f53c5d1b3eb6
Author: Antonioya
Date:   Fri Oct 14 18:35:01 2016 +0200
Branches: blender2.8
https://developer.blender.org/rB6855ba4034158b916122b1d881b3f53c5d1b3eb6

Fix T49614: Grease Pencil GPF error if stroke thickness change too much between 
stroke points

The problem was the function tried to draw a line with one point only. This fix 
will be replaced by new geometry shaders, but we need while this change is not 
ready.

===================================================================

M       source/blender/editors/gpencil/drawgpencil.c

===================================================================

diff --git a/source/blender/editors/gpencil/drawgpencil.c 
b/source/blender/editors/gpencil/drawgpencil.c
index 5564cab..5b886f2 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -642,6 +642,14 @@ static void gp_draw_stroke_3d(const bGPDspoint *points, 
int totpoints, short thi
        float curpressure = points[0].pressure;
        float fpt[3];
        float cyclic_fpt[3];
+       int draw_points = 0;
+
+       /* if cyclic needs one vertex more */
+       int cyclic_add = 0;
+       if (cyclic) {
+               ++cyclic_add;
+       }
+
 
        VertexFormat *format = immVertexFormat();
        unsigned pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
@@ -653,7 +661,7 @@ static void gp_draw_stroke_3d(const bGPDspoint *points, int 
totpoints, short thi
 
        /* draw stroke curve */
        glLineWidth(max_ff(curpressure * thickness, 1.0f));
-       immBeginAtMost(GL_LINE_STRIP, totpoints);
+       immBeginAtMost(GL_LINE_STRIP, totpoints + cyclic_add);
        const bGPDspoint *pt = points;
        for (int i = 0; i < totpoints; i++, pt++) {
                gp_set_point_varying_color(pt, ink, color);
@@ -663,22 +671,33 @@ static void gp_draw_stroke_3d(const bGPDspoint *points, 
int totpoints, short thi
                 * Note: we want more visible levels of pressures when 
thickness is bigger.
                 */
                if (fabsf(pt->pressure - curpressure) > 0.2f / 
(float)thickness) {
+                       /* if the pressure changes before get at least 2 
vertices, need to repeat last point to avoid assert in immEnd() */
+                       if (draw_points < 2) {
+                               const bGPDspoint *pt2 = pt - 1;
+                               mul_v3_m4v3(fpt, diff_mat, &pt2->x);
+                               immVertex3fv(pos, fpt);
+                       }
                        immEnd();
+                       draw_points = 0;
+
                        curpressure = pt->pressure;
                        glLineWidth(max_ff(curpressure * thickness, 1.0f));
-                       immBeginAtMost(GL_LINE_STRIP, totpoints - i + 1);
+                       immBeginAtMost(GL_LINE_STRIP, totpoints - i + 1 + 
cyclic_add);
 
                        /* need to roll-back one point to ensure that there are 
no gaps in the stroke */
                        if (i != 0) { 
                                const bGPDspoint *pt2 = pt - 1;
                                mul_v3_m4v3(fpt, diff_mat, &pt2->x);
+                               gp_set_point_varying_color(pt2, ink, color);
                                immVertex3fv(pos, fpt);
+                               ++draw_points;
                        }
                }
 
                /* now the point we want */
                mul_v3_m4v3(fpt, diff_mat, &pt->x);
                immVertex3fv(pos, fpt);
+               ++draw_points;
 
                if (cyclic && i == 0) {
                        /* save first point to use in cyclic */
@@ -689,6 +708,15 @@ static void gp_draw_stroke_3d(const bGPDspoint *points, 
int totpoints, short thi
        if (cyclic) {
                /* draw line to first point to complete the cycle */
                immVertex3fv(pos, cyclic_fpt);
+               ++draw_points;
+       }
+
+       /* if less of two points, need to repeat last point to avoid assert in 
immEnd() */
+       if (draw_points < 2) {
+               const bGPDspoint *pt2 = pt - 1;
+               mul_v3_m4v3(fpt, diff_mat, &pt2->x);
+               gp_set_point_varying_color(pt2, ink, color);
+               immVertex3fv(pos, fpt);
        }
 
        immEnd();

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to