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
This commit is contained in:
Philipp Oeser 2021-05-30 22:26:31 +02:00
parent c078540512
commit 6899dcab53
Notes: blender-bot 2023-02-13 18:34:07 +01:00
Referenced by issue #88658, Particle animation with Force Field Type:"Force" + Shape:"Curve" crashes Blender on playback if the Curve has only one vertex
1 changed files with 10 additions and 6 deletions

View File

@ -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);
}
}
}
}