[Bf-blender-cvs] [e041d0fc02b] blender-v2.91-release: Fix memory leaks in sculpt mode trimming tools

Pablo Dobarro noreply at git.blender.org
Thu Nov 5 23:39:15 CET 2020


Commit: e041d0fc02b1f0f8e9bc4436accb1ced374aeadd
Author: Pablo Dobarro
Date:   Tue Nov 3 00:01:24 2020 +0100
Branches: blender-v2.91-release
https://developer.blender.org/rBe041d0fc02b1f0f8e9bc4436accb1ced374aeadd

Fix memory leaks in sculpt mode trimming tools

BKE_mesh_free() seems to not free the meshes correctly, so using BKE_id_free() instead.
The looptri array was also not freed.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D9426

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

M	source/blender/editors/sculpt_paint/paint_mask.c

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

diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c
index cc0d20089b4..aec58eb8191 100644
--- a/source/blender/editors/sculpt_paint/paint_mask.c
+++ b/source/blender/editors/sculpt_paint/paint_mask.c
@@ -42,6 +42,7 @@
 #include "BKE_brush.h"
 #include "BKE_ccg.h"
 #include "BKE_context.h"
+#include "BKE_lib_id.h"
 #include "BKE_mesh.h"
 #include "BKE_multires.h"
 #include "BKE_paint.h"
@@ -906,7 +907,7 @@ static void sculpt_gesture_trim_normals_update(SculptGestureContext *sgcontext)
                                             }),
                                             trim_mesh);
   BM_mesh_free(bm);
-  BKE_mesh_free(trim_mesh);
+  BKE_id_free(NULL, trim_mesh);
   trim_operation->mesh = result;
 }
 
@@ -1075,7 +1076,7 @@ static void sculpt_gesture_trim_geometry_generate(SculptGestureContext *sgcontex
 static void sculpt_gesture_trim_geometry_free(SculptGestureContext *sgcontext)
 {
   SculptGestureTrimOperation *trim_operation = (SculptGestureTrimOperation *)sgcontext->operation;
-  BKE_mesh_free(trim_operation->mesh);
+  BKE_id_free(NULL, trim_operation->mesh);
   MEM_freeN(trim_operation->true_mesh_co);
 }
 
@@ -1086,7 +1087,6 @@ static int bm_face_isect_pair(BMFace *f, void *UNUSED(user_data))
 
 static void sculpt_gesture_apply_trim(SculptGestureContext *sgcontext)
 {
-
   SculptGestureTrimOperation *trim_operation = (SculptGestureTrimOperation *)sgcontext->operation;
   Mesh *sculpt_mesh = BKE_mesh_from_object(sgcontext->vc.obact);
   Mesh *trim_mesh = trim_operation->mesh;
@@ -1164,12 +1164,17 @@ static void sculpt_gesture_apply_trim(SculptGestureContext *sgcontext)
     BM_mesh_boolean(bm, looptris, tottri, bm_face_isect_pair, NULL, 2, true, boolean_mode);
   }
 
-  Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, sculpt_mesh);
+  MEM_freeN(looptris);
+
+  Mesh *result = BKE_mesh_from_bmesh_nomain(bm,
+                                            (&(struct BMeshToMeshParams){
+                                                .calc_object_remap = false,
+                                            }),
+                                            sculpt_mesh);
   BM_mesh_free(bm);
   result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
-
-  BKE_mesh_nomain_to_mesh(result, sculpt_mesh, sgcontext->vc.obact, &CD_MASK_MESH, true);
-  BKE_mesh_free(result);
+  BKE_mesh_nomain_to_mesh(
+      result, sgcontext->vc.obact->data, sgcontext->vc.obact, &CD_MASK_MESH, true);
 }
 
 static void sculpt_gesture_trim_begin(bContext *C, SculptGestureContext *sgcontext)



More information about the Bf-blender-cvs mailing list