[Bf-blender-cvs] [c3f971fc103] greasepencil-object: GP: Fix segment fault whith Cutter

Antonioya noreply at git.blender.org
Thu Jan 3 19:50:34 CET 2019


Commit: c3f971fc1039ba69856ec7a379d5d6a954cbdb28
Author: Antonioya
Date:   Thu Jan 3 19:50:21 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBc3f971fc1039ba69856ec7a379d5d6a954cbdb28

GP: Fix segment fault whith Cutter

The problem was when the new intersection point was inside the lasso.

Also improved when select all stroke points.

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

M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_utils.c

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

diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index ee288b7e705..504e191fb9f 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -3738,7 +3738,7 @@ typedef bool(*GPencilTestFn)(
 	bGPDstroke *gps, bGPDspoint *pt,
 	const GP_SpaceConversion *gsc, const float diff_mat[4][4], void *user_data);
 
-void gpencil_cutter_dissolve(bGPdata *gpd, bGPDlayer *hit_layer, bGPDstroke *hit_stroke)
+static void gpencil_cutter_dissolve(bGPdata *gpd, bGPDlayer *hit_layer, bGPDstroke *hit_stroke)
 {
 	bGPDspoint *pt = NULL;
 	bGPDspoint *pt1 = NULL;
@@ -3746,8 +3746,15 @@ void gpencil_cutter_dissolve(bGPdata *gpd, bGPDlayer *hit_layer, bGPDstroke *hit
 
 	bGPDstroke *gpsn = hit_stroke->next;
 
-	/* if only one point delete */
-	if ((hit_stroke) && (hit_stroke->totpoints == 1)) {
+	int totselect = 0;
+	for (i = 0, pt = hit_stroke->points; i < hit_stroke->totpoints; i++, pt++) {
+		if (pt->flag & GP_SPOINT_SELECT) {
+			totselect++;
+		}
+	}
+
+	/* if all points selected delete */
+	if (hit_stroke->totpoints == totselect) {
 		BLI_remlink(&hit_layer->actframe->strokes, hit_stroke);
 		BKE_gpencil_free_stroke(hit_stroke);
 		hit_stroke = NULL;
@@ -3765,12 +3772,15 @@ void gpencil_cutter_dissolve(bGPdata *gpd, bGPDlayer *hit_layer, bGPDstroke *hit
 	}
 
 	if (hit_stroke) {
-		/* tag and dissolve */
+		/* tag and dissolve (untag new points) */
 		for (i = 0, pt = hit_stroke->points; i < hit_stroke->totpoints; i++, pt++) {
 			if (pt->flag & GP_SPOINT_SELECT) {
 				pt->flag &= ~GP_SPOINT_SELECT;
 				pt->flag |= GP_SPOINT_TAG;
 			}
+			else if (pt->flag & GP_SPOINT_TAG) {
+				pt->flag &= ~GP_SPOINT_TAG;
+			}
 		}
 		gp_stroke_delete_tagged_points(
 			hit_layer->actframe, hit_stroke, gpsn, GP_SPOINT_TAG, false, 1);
@@ -3816,20 +3826,31 @@ static int gpencil_cutter_lasso_select(
 	/* select points */
 	GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps)
 	{
+		int tot_inside = 0;
 		for (i = 0; i < gps->totpoints; i++) {
 			pt = &gps->points[i];
-			if (pt->flag & GP_SPOINT_SELECT) {
+			if ((pt->flag & GP_SPOINT_SELECT) || (pt->flag & GP_SPOINT_TAG)) {
 				continue;
 			}
 			/* convert point coords to screenspace */
 			const bool is_inside = is_inside_fn(gps, pt, &gsc, gpstroke_iter.diff_mat, user_data);
 			if (is_inside) {
+				tot_inside++;
 				changed = true;
 				pt->flag |= GP_SPOINT_SELECT;
 				gps->flag |= GP_STROKE_SELECT;
 				float r_hita[3], r_hitb[3];
-				ED_gpencil_select_stroke_segment(
-					gpd, gpl, gps, pt, true, true, r_hita, r_hitb);
+				if (gps->totpoints > 1) {
+					ED_gpencil_select_stroke_segment(
+						gpd, gpl, gps, pt, true, true, r_hita, r_hitb);
+				}
+			}
+		}
+		/* if mark all points inside lasso set to remove all stroke */
+		if (tot_inside == gps->totpoints) {
+			for (i = 0; i < gps->totpoints; i++) {
+				pt = &gps->points[i];
+				pt->flag |= GP_SPOINT_SELECT;
 			}
 		}
 	}
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index d0dac7b06d3..41453dabc6f 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2066,6 +2066,8 @@ void static gp_insert_point(
 
 			/* unselect */
 			pt_final->flag &= ~GP_SPOINT_SELECT;
+			/* tag to avoid more checking with this point */
+			pt_final->flag |= GP_SPOINT_TAG;
 		}
 
 		i2++;



More information about the Bf-blender-cvs mailing list