Fix (unreported) MOD_surface: raw calloc on non-trivial data.

It seems that this was 'fine', as non-trivial data in `BVHTreeFromMesh`
appear to be 'safe' when simply zero-initialized instead of being
properly constructed.

Note that this 'calloced' data was already 'MEM_deleted', this is
currently considered as a valid use-case unfortunately, otherwise the
issue would have been detected earlier.

Directly use 'copy' `MEM_new` code instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/135862
This commit is contained in:
Bastien Montagne
2025-03-12 14:35:36 +01:00
committed by Gitea
parent 58d34984d2
commit f36f9bdb87

View File

@@ -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<blender::bke::BVHTreeFromMesh *>(
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<blender::bke::BVHTreeFromMesh>(
__func__, surmd->runtime.mesh->bvh_corner_tris());
}
else if (has_edge) {
surmd->runtime.bvhtree = MEM_new<blender::bke::BVHTreeFromMesh>(
__func__, surmd->runtime.mesh->bvh_edges());
}
}
}