From 0af8ad51c07f987d8cf449efd95a7068f7edeffa Mon Sep 17 00:00:00 2001 From: Antonioya Date: Mon, 21 Jan 2019 17:38:47 +0100 Subject: GP: Fix memory leaks when use cutter with weights There were some issues when copy the weights and other memory leaks. Also some code cleanup. --- source/blender/editors/gpencil/gpencil_utils.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source/blender/editors/gpencil/gpencil_utils.c') diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 226a2bc7a98..776576807b4 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -2057,6 +2057,11 @@ static bool gpencil_check_collision( static void gp_copy_points( bGPDstroke *gps, bGPDspoint *pt, bGPDspoint *pt_final, int i, int i2) { + /* don't copy same point */ + if (i == i2) { + return; + } + copy_v3_v3(&pt_final->x, &pt->x); pt_final->pressure = pt->pressure; pt_final->strength = pt->strength; @@ -2068,9 +2073,16 @@ static void gp_copy_points( if (gps->dvert != NULL) { MDeformVert *dvert = &gps->dvert[i]; MDeformVert *dvert_final = &gps->dvert[i2]; + MEM_SAFE_FREE(dvert_final->dw); dvert_final->totweight = dvert->totweight; - dvert_final->dw = dvert->dw; + if (dvert->dw == NULL) { + dvert_final->dw = NULL; + dvert_final->totweight = 0; + } + else { + dvert_final->dw = MEM_dupallocN(dvert->dw); + } } } -- cgit v1.2.3