[Bf-blender-cvs] [dd350c0] blender2.8: GPencil: Avoid assert error if the immEnd is called with only one point for lines

Antonioya noreply at git.blender.org
Fri Oct 14 19:26:29 CEST 2016


Commit: dd350c0b37052c0dfb2436fc671cdaf57e065c13
Author: Antonioya
Date:   Fri Oct 14 19:24:27 2016 +0200
Branches: blender2.8
https://developer.blender.org/rBdd350c0b37052c0dfb2436fc671cdaf57e065c13

GPencil: Avoid assert error if the immEnd is called with only one point for lines

This function will be replace by geometry shader, but we need this fix until the shader will be ready. The problem is similar to T49614.

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

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

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

diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 5b886f2..dd2f6d0 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -190,6 +190,8 @@ static void gp_draw_stroke_buffer_fill(tGPspoint *points, int totpoints, float i
 static void gp_draw_stroke_buffer(const tGPspoint *points, int totpoints, short thickness,
                                   short dflag, short sflag, float ink[4], float fill_ink[4])
 {
+	int draw_points = 0;
+
 	/* error checking */
 	if ((points == NULL) || (totpoints <= 0))
 		return;
@@ -234,7 +236,15 @@ static void gp_draw_stroke_buffer(const tGPspoint *points, int totpoints, short
 			 * and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP)
 			 */
 			if (fabsf(pt->pressure - oldpressure) > 0.2f) {
+				/* need to have 2 points to avoid immEnd assert error */
+				if (draw_points < 2) {
+					gp_set_tpoint_varying_color(pt - 1, ink, color);
+					immVertex2iv(pos, &(pt - 1)->x);
+				}
+
 				immEnd();
+				draw_points = 0;
+
 				glLineWidth(max_ff(pt->pressure * thickness, 1.0f));
 				immBeginAtMost(GL_LINE_STRIP, totpoints - i + 1);
 
@@ -242,6 +252,7 @@ static void gp_draw_stroke_buffer(const tGPspoint *points, int totpoints, short
 				if (i != 0) { 
 					gp_set_tpoint_varying_color(pt - 1, ink, color);
 					immVertex2iv(pos, &(pt - 1)->x);
+					++draw_points;
 				}
 
 				oldpressure = pt->pressure; /* reset our threshold */
@@ -250,6 +261,12 @@ static void gp_draw_stroke_buffer(const tGPspoint *points, int totpoints, short
 			/* now the point we want */
 			gp_set_tpoint_varying_color(pt, ink, color);
 			immVertex2iv(pos, &pt->x);
+			++draw_points;
+		}
+		/* need to have 2 points to avoid immEnd assert error */
+		if (draw_points < 2) {
+			gp_set_tpoint_varying_color(pt - 1, ink, color);
+			immVertex2iv(pos, &(pt - 1)->x);
 		}
 
 		if (G.debug & G_DEBUG) setlinestyle(0);




More information about the Bf-blender-cvs mailing list