diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-06-24 15:09:40 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-06-24 15:13:27 +0300 |
commit | dd328be0f08bc79125f9bc862d814e49c213b2f3 (patch) | |
tree | 8a9251ced6d07ad353ee58da2000adee29468d20 /source/blender | |
parent | 074929d1c5f5b0e9a4da3c3058cc9f3038fb2910 (diff) |
Fix memory leak calculating deform modifiers in edit-mode
This bug goes back to 2.80 but doesn't seem to have been reported.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh_runtime.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_runtime.c | 31 |
3 files changed, 22 insertions, 14 deletions
diff --git a/source/blender/blenkernel/BKE_mesh_runtime.h b/source/blender/blenkernel/BKE_mesh_runtime.h index fdddafcc71f..468ec6a44cd 100644 --- a/source/blender/blenkernel/BKE_mesh_runtime.h +++ b/source/blender/blenkernel/BKE_mesh_runtime.h @@ -49,6 +49,7 @@ void BKE_mesh_runtime_looptri_recalc(struct Mesh *mesh); const struct MLoopTri *BKE_mesh_runtime_looptri_ensure(struct Mesh *mesh); bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh); bool BKE_mesh_runtime_clear_edit_data(struct Mesh *mesh); +bool BKE_mesh_runtime_reset_edit_data(struct Mesh *mesh); void BKE_mesh_runtime_clear_geometry(struct Mesh *mesh); void BKE_mesh_runtime_clear_cache(struct Mesh *mesh); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index b4e2cd772c9..8a5be6b9cb3 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -1669,7 +1669,9 @@ static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph, else { Mesh *me_orig = mesh_input; if (me_orig->id.tag & LIB_TAG_COPIED_ON_WRITE) { - BKE_mesh_runtime_ensure_edit_data(me_orig); + if (!BKE_mesh_runtime_ensure_edit_data(me_orig)) { + BKE_mesh_runtime_reset_edit_data(me_orig); + } me_orig->runtime.edit_data->vertexCos = MEM_dupallocN(deformed_verts); } mesh_cage = BKE_mesh_wrapper_from_editmesh_with_coords( diff --git a/source/blender/blenkernel/intern/mesh_runtime.c b/source/blender/blenkernel/intern/mesh_runtime.c index 8bce577897b..932423bc445 100644 --- a/source/blender/blenkernel/intern/mesh_runtime.c +++ b/source/blender/blenkernel/intern/mesh_runtime.c @@ -203,26 +203,31 @@ bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh) return true; } +bool BKE_mesh_runtime_reset_edit_data(Mesh *mesh) +{ + EditMeshData *edit_data = mesh->runtime.edit_data; + if (edit_data == NULL) { + return false; + } + + MEM_SAFE_FREE(edit_data->polyCos); + MEM_SAFE_FREE(edit_data->polyNos); + MEM_SAFE_FREE(edit_data->vertexCos); + MEM_SAFE_FREE(edit_data->vertexNos); + + return true; +} + bool BKE_mesh_runtime_clear_edit_data(Mesh *mesh) { if (mesh->runtime.edit_data == NULL) { return false; } + BKE_mesh_runtime_reset_edit_data(mesh); - if (mesh->runtime.edit_data->polyCos != NULL) { - MEM_freeN((void *)mesh->runtime.edit_data->polyCos); - } - if (mesh->runtime.edit_data->polyNos != NULL) { - MEM_freeN((void *)mesh->runtime.edit_data->polyNos); - } - if (mesh->runtime.edit_data->vertexCos != NULL) { - MEM_freeN((void *)mesh->runtime.edit_data->vertexCos); - } - if (mesh->runtime.edit_data->vertexNos != NULL) { - MEM_freeN((void *)mesh->runtime.edit_data->vertexNos); - } + MEM_freeN(mesh->runtime.edit_data); + mesh->runtime.edit_data = NULL; - MEM_SAFE_FREE(mesh->runtime.edit_data); return true; } |