diff --git a/source/blender/modifiers/intern/MOD_surface.cc b/source/blender/modifiers/intern/MOD_surface.cc index 72f256508e3..fbaaa7c1e92 100644 --- a/source/blender/modifiers/intern/MOD_surface.cc +++ b/source/blender/modifiers/intern/MOD_surface.cc @@ -57,10 +57,7 @@ static void free_data(ModifierData *md) SurfaceModifierData *surmd = (SurfaceModifierData *)md; if (surmd) { - if (surmd->runtime.bvhtree) { - MEM_delete(surmd->runtime.bvhtree); - surmd->runtime.bvhtree = nullptr; - } + MEM_SAFE_DELETE(surmd->runtime.bvhtree); if (surmd->runtime.mesh) { BKE_id_free(nullptr, surmd->runtime.mesh); @@ -87,9 +84,7 @@ static void deform_verts(ModifierData *md, const int cfra = int(DEG_get_ctime(ctx->depsgraph)); /* Free mesh and BVH cache. */ - MEM_delete(surmd->runtime.bvhtree); - surmd->runtime.bvhtree = nullptr; - + MEM_SAFE_DELETE(surmd->runtime.bvhtree); if (surmd->runtime.mesh) { BKE_id_free(nullptr, surmd->runtime.mesh); surmd->runtime.mesh = nullptr; @@ -150,16 +145,13 @@ static void deform_verts(ModifierData *md, const bool has_face = surmd->runtime.mesh->faces_num > 0; const bool has_edge = surmd->runtime.mesh->edges_num > 0; - if (has_face || has_edge) { - surmd->runtime.bvhtree = static_cast( - MEM_callocN(sizeof(blender::bke::BVHTreeFromMesh), __func__)); - - if (has_face) { - *surmd->runtime.bvhtree = surmd->runtime.mesh->bvh_corner_tris(); - } - else if (has_edge) { - *surmd->runtime.bvhtree = surmd->runtime.mesh->bvh_edges(); - } + if (has_face) { + surmd->runtime.bvhtree = MEM_new( + __func__, surmd->runtime.mesh->bvh_corner_tris()); + } + else if (has_edge) { + surmd->runtime.bvhtree = MEM_new( + __func__, surmd->runtime.mesh->bvh_edges()); } } }