diff options
author | Philipp Oeser <info@graphics-engineer.com> | 2021-05-30 23:26:31 +0300 |
---|---|---|
committer | Philipp Oeser <info@graphics-engineer.com> | 2021-06-01 14:38:29 +0300 |
commit | 6899dcab5339d1f17dd2ea665a38e4ab28ab23fc (patch) | |
tree | 225aaccf542fa172b34def49554918c6071db062 /source/blender/modifiers/intern/MOD_surface.c | |
parent | c078540512722e465e8cfc555dd958827b378a11 (diff) |
Fix T88658: Force Fields of curve shape can crash if curve has only one point
`bvhtree_from_mesh_edges_create_tree` can actually leave the BVHTree
NULL (e.g. if no edges are present).
Now dont allocate `BVHTreeFromMesh` on the `SurfaceModifierData` at all
in case the tree would be NULL anyways.
Places like `get_effector_data` check for `SurfaceModifierData`-
>`BVHTreeFromMesh` and dont try to stuff like getting a closest point on
surface, which would crash as soon as BVHNodes would need to be accessed
(from the NULL BVHTree).
Maniphest Tasks: T88658
Differential Revision: https://developer.blender.org/D11443
Diffstat (limited to 'source/blender/modifiers/intern/MOD_surface.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_surface.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c index d2c011a21d3..bfd4cd81803 100644 --- a/source/blender/modifiers/intern/MOD_surface.c +++ b/source/blender/modifiers/intern/MOD_surface.c @@ -184,13 +184,17 @@ static void deformVerts(ModifierData *md, surmd->cfra = cfra; - surmd->bvhtree = MEM_callocN(sizeof(BVHTreeFromMesh), "BVHTreeFromMesh"); + const bool has_poly = surmd->mesh->totpoly > 0; + const bool has_edge = surmd->mesh->totedge > 0; + if (has_poly || has_edge) { + surmd->bvhtree = MEM_callocN(sizeof(BVHTreeFromMesh), "BVHTreeFromMesh"); - if (surmd->mesh->totpoly) { - BKE_bvhtree_from_mesh_get(surmd->bvhtree, surmd->mesh, BVHTREE_FROM_LOOPTRI, 2); - } - else { - BKE_bvhtree_from_mesh_get(surmd->bvhtree, surmd->mesh, BVHTREE_FROM_EDGES, 2); + if (has_poly) { + BKE_bvhtree_from_mesh_get(surmd->bvhtree, surmd->mesh, BVHTREE_FROM_LOOPTRI, 2); + } + else if (has_edge) { + BKE_bvhtree_from_mesh_get(surmd->bvhtree, surmd->mesh, BVHTREE_FROM_EDGES, 2); + } } } } |