Commit: a6f5adb83698262aec9360d8850cab4536982208
Author: Antonio Vazquez
Date:   Thu Aug 10 17:11:58 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBa6f5adb83698262aec9360d8850cab4536982208

Fix Lattice memory leak

The loop need to free memory to avoid memory leak

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

M       source/blender/blenkernel/BKE_gpencil.h
M       source/blender/blenkernel/intern/gpencil_modifier.c
M       source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h 
b/source/blender/blenkernel/BKE_gpencil.h
index e7d5b57e28d..5f00e326404 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -178,6 +178,7 @@ void BKE_gpencil_simplify_stroke(struct bGPDlayer *gpl, 
struct bGPDstroke *gps,
 
 bool BKE_gpencil_use_this_lattice(struct Object *ob, struct Object *lattice);
 void BKE_gpencil_lattice_init(struct Object *ob);
+void BKE_gpencil_lattice_clear(struct Object *ob);
 void BKE_gpencil_lattice_modifier(int id, struct GpencilLatticeModifierData 
*mmd, struct Object *ob, struct bGPDlayer *gpl, struct bGPDstroke *gps);
 
 #endif /*  __BKE_GPENCIL_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c 
b/source/blender/blenkernel/intern/gpencil_modifier.c
index 284ecb09ac6..db3e738c596 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -684,6 +684,21 @@ void BKE_gpencil_lattice_init(Object *ob)
        }
 }
 
+/* clear lattice deform data */
+void BKE_gpencil_lattice_clear(Object *ob)
+{
+       ModifierData *md;
+       for (md = ob->modifiers.first; md; md = md->next) {
+               if (md->type == eModifierType_GpencilLattice) {
+                       GpencilLatticeModifierData *mmd = 
(GpencilLatticeModifierData *)md;
+                       if ((mmd) && (mmd->cache_data)) {
+                               end_latt_deform((LatticeDeformData 
*)mmd->cache_data);
+                               mmd->cache_data = NULL;
+                       }
+               }
+       }
+}
+
 /* apply lattice to stroke */
 void BKE_gpencil_lattice_modifier(int UNUSED(id), GpencilLatticeModifierData 
*mmd, Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
 {
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c 
b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 321ea46e6e9..9e01ab829f4 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -897,6 +897,12 @@ void DRW_gpencil_populate_datablock(GPENCIL_e_data 
*e_data, void *vedata, Scene
                gpencil_draw_strokes(cache, e_data, vedata, ts, ob, gpd, gpl, 
gpf, derived_gpf, 
                        gpl->opacity, gpl->tintcolor, false, false);
        }
+
+       /* clear any lattice data */
+       if ((cache->is_dirty) && (ob->modifiers.first)) {
+               BKE_gpencil_lattice_clear(ob);
+       }
+
        cache->is_dirty = false;
 }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to