[Bf-blender-cvs] [0af8ad51c07] master: GP: Fix memory leaks when use cutter with weights
Antonioya
noreply at git.blender.org
Mon Jan 21 17:39:06 CET 2019
Commit: 0af8ad51c07f987d8cf449efd95a7068f7edeffa
Author: Antonioya
Date: Mon Jan 21 17:38:47 2019 +0100
Branches: master
https://developer.blender.org/rB0af8ad51c07f987d8cf449efd95a7068f7edeffa
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.
===================================================================
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 e81aac3686f..05bd5dd3c1b 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -1843,7 +1843,6 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke
bool in_island = false;
int num_islands = 0;
-
/* First Pass: Identify start/end of islands */
bGPDspoint *pt = gps->points;
for (int i = 0; i < gps->totpoints; i++, pt++) {
@@ -1902,13 +1901,14 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke
/* Copy weights */
int e = island->start_idx;
for (int i = 0; i < new_stroke->totpoints; i++) {
- MDeformVert *dvert_dst = &gps->dvert[e];
- MDeformVert *dvert_src = &new_stroke->dvert[i];
- dvert_dst->dw = MEM_dupallocN(dvert_src->dw);
+ MDeformVert *dvert_src = &gps->dvert[e];
+ MDeformVert *dvert_dst = &new_stroke->dvert[i];
+ if (dvert_src->dw) {
+ dvert_dst->dw = MEM_dupallocN(dvert_src->dw);
+ }
e++;
}
}
-
/* Each island corresponds to a new stroke. We must adjust the
* timings of these new strokes:
*
@@ -1954,17 +1954,8 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke
MEM_freeN(islands);
/* Delete the old stroke */
- 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);
+ BLI_remlink(&gpf->strokes, gps);
+ BKE_gpencil_free_stroke(gps);
}
/* Split selected strokes into segments, splitting on selected points */
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);
+ }
}
}
More information about the Bf-blender-cvs
mailing list