[Bf-blender-cvs] [13d411ccba4] experimental_gp_weight: Cleanup free code

Antonio Vazquez noreply at git.blender.org
Tue May 15 20:12:54 CEST 2018


Commit: 13d411ccba47a399a58dfacae65dd56a9bd7b75e
Author: Antonio Vazquez
Date:   Tue May 15 20:12:41 2018 +0200
Branches: experimental_gp_weight
https://developer.blender.org/rB13d411ccba47a399a58dfacae65dd56a9bd7b75e

Cleanup free code

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

M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_paint.c

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

diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index f2c6a1ea5a4..4d19615eee1 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -113,7 +113,6 @@ void BKE_gpencil_free_stroke_weights(bGPDstroke *gps)
 	for (int i = 0; i < gps->totpoints; i++) {
 		MDeformVert *dvert = &gps->dvert[i];
 		BKE_gpencil_free_point_weights(dvert);
-		MEM_freeN(dvert);
 	}
 }
 
@@ -125,9 +124,12 @@ void BKE_gpencil_free_stroke(bGPDstroke *gps)
 	}
 	/* free stroke memory arrays, then stroke itself */
 	if (gps->points) {
-		BKE_gpencil_free_stroke_weights(gps);
 		MEM_freeN(gps->points);
 	}
+	if (gps->dvert) {
+		BKE_gpencil_free_stroke_weights(gps);
+		MEM_freeN(gps->dvert);
+	}
 	if (gps->triangles)
 		MEM_freeN(gps->triangles);
 
@@ -516,7 +518,8 @@ bGPDstroke *BKE_gpencil_add_stroke(bGPDframe *gpf, int mat_idx, int totpoints, s
 	
 	gps->totpoints = totpoints;
 	gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
-	
+	gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
+
 	/* initialize triangle memory to dummy data */
 	gps->triangles = MEM_callocN(sizeof(bGPDtriangle), "GP Stroke triangulation");
 	gps->flag |= GP_STROKE_RECALC_CACHES;
@@ -543,9 +546,15 @@ void BKE_gpencil_stroke_weights_duplicate(bGPDstroke *gps_src, bGPDstroke *gps_d
 	BLI_assert(gps_src->totpoints == gps_dst->totpoints);
 
 	for (int i = 0; i < gps_src->totpoints; i++) {
-		MDeformVert *dvert_dst = &gps_dst->dvert[i];
 		MDeformVert *dvert_src = &gps_src->dvert[i];
-		dvert_dst->dw = MEM_dupallocN(dvert_src->dw);
+		MDeformVert *dvert_dst = &gps_dst->dvert[i];
+		if (dvert_src->dw) {
+			dvert_dst->dw = MEM_dupallocN(dvert_src->dw);
+		}
+		else {
+			dvert_dst->totweight = 0;
+			dvert_dst->dw = NULL;
+		}
 	}
 }
 
@@ -765,9 +774,12 @@ void BKE_gpencil_frame_delete_laststroke(bGPDlayer *gpl, bGPDframe *gpf)
 	
 	/* free the stroke and its data */
 	if (gps->points) {
-		BKE_gpencil_free_stroke_weights(gps);
 		MEM_freeN(gps->points);
 	}
+	if (gps->dvert) {
+		BKE_gpencil_free_stroke_weights(gps);
+		MEM_freeN(gps->dvert);
+	}
 	MEM_freeN(gps->triangles);
 	BLI_freelinkN(&gpf->strokes, gps);
 	
@@ -1649,9 +1661,12 @@ void BKE_gpencil_material_index_remove(bGPdata *gpd, int index)
 					gpsn = gps->next;
 					if (gps->mat_nr == index) {
 						if (gps->points) {
-							BKE_gpencil_free_stroke_weights(gps);
 							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);
 					}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 66a0b288b41..7484cca5eba 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6353,8 +6353,9 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
 			for (gps = gpf->strokes.first; gps; gps = gps->next) {
 				/* relink stroke points array */
 				gps->points = newdataadr(fd, gps->points);
-				/* relink point weight data */
-				direct_link_dverts(fd,gps->totpoints, gps->dvert);
+				
+				/* relink weight data */
+				direct_link_dverts(fd, gps->totpoints, gps->dvert);
 
 				/* the triangulation is not saved, so need to be recalculated */
 				gps->triangles = NULL;
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 98bf84084b4..ee5aa29dbb0 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -472,9 +472,12 @@ static int gp_frame_clean_fill_exec(bContext *C, wmOperator *op)
 					if (gps->flag & GP_STROKE_NOFILL) {
 						/* free stroke memory arrays, then stroke itself */
 						if (gps->points) {
-							BKE_gpencil_free_stroke_weights(gps);
 							MEM_freeN(gps->points);
 						}
+						if (gps->dvert) {
+							BKE_gpencil_free_stroke_weights(gps);
+							MEM_freeN(gps->dvert);
+						}
 						MEM_SAFE_FREE(gps->triangles);
 						BLI_freelinkN(&gpf->strokes, gps);
 
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index df85e8de56e..6e6785c3535 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -725,9 +725,13 @@ void ED_gpencil_strokes_copybuf_free(void)
 		gpsn = gps->next;
 		
 		if (gps->points) {
-			BKE_gpencil_free_stroke_weights(gps);
 			MEM_freeN(gps->points);
 		}
+		if (gps->dvert) {
+			BKE_gpencil_free_stroke_weights(gps);
+			MEM_freeN(gps->dvert);
+		}
+
 		MEM_SAFE_FREE(gps->triangles);
 
 		BLI_freelinkN(&gp_strokes_copypastebuf, gps);
@@ -1400,9 +1404,12 @@ static int gp_delete_selected_strokes(bContext *C)
 					if (gps->flag & GP_STROKE_SELECT) {
 						/* free stroke memory arrays, then stroke itself */
 						if (gps->points) {
-							BKE_gpencil_free_stroke_weights(gps);
 							MEM_freeN(gps->points);
 						}
+						if (gps->dvert) {
+							BKE_gpencil_free_stroke_weights(gps);
+							MEM_freeN(gps->dvert);
+						}
 						MEM_SAFE_FREE(gps->triangles);
 						BLI_freelinkN(&gpf->strokes, gps);
 
@@ -1519,9 +1526,12 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode)
 						if (tot <= 0) {
 							/* remove the entire stroke */
 							if (gps->points) {
-								BKE_gpencil_free_stroke_weights(gps);
 								MEM_freeN(gps->points);
 							}
+							if (gps->dvert) {
+								BKE_gpencil_free_stroke_weights(gps);
+								MEM_freeN(gps->dvert);
+							}
 							if (gps->triangles) {
 								MEM_freeN(gps->triangles);
 							}
@@ -1592,9 +1602,12 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode)
 
 							/* free the old buffer */
 							if (gps->points) {
-								BKE_gpencil_free_stroke_weights(gps);
 								MEM_freeN(gps->points);
 							}
+							if (gps->dvert) {
+								BKE_gpencil_free_stroke_weights(gps);
+								MEM_freeN(gps->dvert);
+							}
 
 							/* save the new buffer */
 							gps->points = new_points;
@@ -1761,9 +1774,12 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke
 	
 	/* Delete the old stroke */
 	if (gps->points) {
-		BKE_gpencil_free_stroke_weights(gps);
 		MEM_freeN(gps->points);
 	}
+	if (gps->dvert) {
+		BKE_gpencil_free_stroke_weights(gps);
+		MEM_freeN(gps->dvert);
+	}
 	if (gps->triangles) {
 		MEM_freeN(gps->triangles);
 	}
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index dd933d42b14..67a7949411e 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -963,6 +963,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
 
 	gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
 	gps->dvert = MEM_callocN(sizeof(MDeformVert) * gps->totpoints, "gp_stroke_weights");
+
 	/* initialize triangle memory to dummy data */
 	gps->triangles = MEM_callocN(sizeof(bGPDtriangle), "GP Stroke triangulation");
 	gps->flag |= GP_STROKE_RECALC_CACHES;
@@ -1248,9 +1249,14 @@ static float gp_stroke_eraser_calc_influence(tGPsdata *p, const int mval[2], con
 static void gp_free_stroke(bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps)
 {
 	if (gps->points) {
-		BKE_gpencil_free_stroke_weights(gps);
 		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);



More information about the Bf-blender-cvs mailing list