[Bf-blender-cvs] [7e6beb70ad6] greasepencil-object: Cleanup: Deduplicate stroke freeing code

Joshua Leung noreply at git.blender.org
Mon Jul 9 06:08:05 CEST 2018


Commit: 7e6beb70ad66bfcf540f49ed95cb549cc4d66721
Author: Joshua Leung
Date:   Mon Jul 9 14:55:34 2018 +1200
Branches: greasepencil-object
https://developer.blender.org/rB7e6beb70ad66bfcf540f49ed95cb549cc4d66721

Cleanup: Deduplicate stroke freeing code

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

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

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

diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index 17d1143aba7..dbd55e95f64 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -817,6 +817,27 @@ static float view3d_point_depth(const RegionView3D *rv3d, const float co[3])
 	}
 }
 
+/* helper to free a stroke
+ * NOTE: gps->dvert and gps->triangles should be NULL, but check anyway for good measure
+ */
+static void gp_free_stroke(bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps)
+{
+	if (gps->points) {
+		MEM_freeN(gps->points);
+	}
+
+	if (gps->dvert) {
+		BKE_gpencil_free_stroke_weights(gps);
+		MEM_freeN(gps->dvert);
+	}
+
+	if (gps->triangles) {
+		MEM_freeN(gps->triangles);
+	}
+
+	BLI_freelinkN(&gpf->strokes, gps);
+}
+
 /* only erase stroke points that are visible */
 static bool gp_stroke_eraser_is_occluded(tGPsdata *p, const bGPDspoint *pt, const int x, const int y)
 {
@@ -870,11 +891,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
 
 	if (gps->totpoints == 0) {
 		/* just free stroke */
-		if (gps->points)
-			MEM_freeN(gps->points);
-		if (gps->triangles)
-			MEM_freeN(gps->triangles);
-		BLI_freelinkN(&gpf->strokes, gps);
+		gp_free_stroke(p->gpd, gpf, gps);
 	}
 	else if (gps->totpoints == 1) {
 		/* only process if it hasn't been masked out... */
@@ -886,11 +903,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
 				/* only check if point is inside */
 				if (len_v2v2_int(mval, pc1) <= radius) {
 					/* free stroke */
-					// XXX: pressure sensitive eraser should apply here too?
-					MEM_freeN(gps->points);
-					if (gps->triangles)
-						MEM_freeN(gps->triangles);
-					BLI_freelinkN(&gpf->strokes, gps);
+					gp_free_stroke(p->gpd, gpf, gps);
 				}
 			}
 		}



More information about the Bf-blender-cvs mailing list