[Bf-blender-cvs] [fa6c2c7dba9] master: GPencil: Handle vertex groups weights correctly

Antonioya noreply at git.blender.org
Mon Apr 1 16:48:06 CEST 2019


Commit: fa6c2c7dba909e5d8a88817854b215990eea7051
Author: Antonioya
Date:   Mon Apr 1 16:47:01 2019 +0200
Branches: master
https://developer.blender.org/rBfa6c2c7dba909e5d8a88817854b215990eea7051

GPencil: Handle vertex groups weights correctly

In extrude operator when the point was added, the weight data pointer was wrongly connected to old pointer.

Now, when move the data, the pointer is moved, but when a new point is added, the memory is duplicated to keep separated copies of the pointer.

This is related T62872

Thanks to @sergey for his help fixing this bug.

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

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

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

diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index b6499200e01..99d37f87da7 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -757,11 +757,11 @@ void GPENCIL_OT_duplicate(wmOperatorType *ot)
 /* ************** Extrude Selected Strokes **************** */
 
 /* helper to copy a point to temp area */
-static void copy_point(
+static void copy_move_point(
         bGPDstroke *gps,
         bGPDspoint *temp_points,
         MDeformVert *temp_dverts,
-        int from_idx, int to_idx)
+        int from_idx, int to_idx, const bool copy)
 {
 	bGPDspoint *pt = &temp_points[from_idx];
 	bGPDspoint *pt_final = &gps->points[to_idx];
@@ -779,7 +779,13 @@ static void copy_point(
 		MDeformVert *dvert_final = &gps->dvert[to_idx];
 
 		dvert_final->totweight = dvert->totweight;
-		dvert_final->dw = dvert->dw;
+		/* if copy, duplicate memory, otherwise move only the pointer */
+		if (copy) {
+			dvert_final->dw = MEM_dupallocN(dvert->dw);
+		}
+		else {
+			dvert_final->dw = dvert->dw;
+		}
 	}
 }
 
@@ -822,7 +828,7 @@ static void gpencil_add_move_points(bGPDframe *gpf, bGPDstroke *gps)
 			BLI_insertlinkafter(&gpf->strokes, gps, gps_new);
 
 			/* copy selected point data to new stroke */
-			copy_point(gps_new, gps->points, gps->dvert, i, 0);
+			copy_move_point(gps_new, gps->points, gps->dvert, i, 0, true);
 
 			/* deselect orinal point */
 			pt->flag &= ~GP_SPOINT_SELECT;
@@ -863,14 +869,14 @@ static void gpencil_add_move_points(bGPDframe *gpf, bGPDstroke *gps)
 
 		/* move points to new position */
 		for (int i = 0; i < oldtotpoints; i++) {
-			copy_point(gps, temp_points, temp_dverts, i, i2);
+			copy_move_point(gps, temp_points, temp_dverts, i, i2, false);
 			i2++;
 		}
 		gps->flag |= GP_STROKE_RECALC_GEOMETRY;
 
 		/* if first point, add new point at the begining */
 		if (do_first) {
-			copy_point(gps, temp_points, temp_dverts, 0, 0);
+			copy_move_point(gps, temp_points, temp_dverts, 0, 0, true);
 			/* deselect old */
 			pt = &gps->points[1];
 			pt->flag &= ~GP_SPOINT_SELECT;
@@ -881,9 +887,9 @@ static void gpencil_add_move_points(bGPDframe *gpf, bGPDstroke *gps)
 
 		/* if last point, add new point at the end */
 		if (do_last) {
-			copy_point(
+			copy_move_point(
 			        gps, temp_points, temp_dverts,
-			        oldtotpoints - 1, gps->totpoints - 1);
+			        oldtotpoints - 1, gps->totpoints - 1, true);
 
 			/* deselect old */
 			pt = &gps->points[gps->totpoints - 2];



More information about the Bf-blender-cvs mailing list