MOD_cast: do not compute mesh when not needed.

This modifier only uses mesh to get vgroup, which is only needed in case
modified object is indeed a mesh! Building a mesh from curve here is not
only useless and time-consuming, it will also easily fail the assert
about same number of vertices!

Also fixes crash when used on lattice.

Related to T57972.
This commit is contained in:
Bastien Montagne 2018-11-26 11:30:46 +01:00
parent c1adf938e6
commit 8cd5edf850
1 changed files with 7 additions and 3 deletions

View File

@ -429,9 +429,13 @@ static void deformVerts(
int numVerts)
{
CastModifierData *cmd = (CastModifierData *)md;
Mesh *mesh_src = MOD_get_mesh_eval(ctx->object, NULL, mesh, NULL, false, false);
Mesh *mesh_src = NULL;
BLI_assert(mesh_src->totvert == numVerts);
if (ctx->object->type == OB_MESH) {
/* mesh_src is only needed for vgroups. */
mesh_src = MOD_get_mesh_eval(ctx->object, NULL, mesh, NULL, false, false);
BLI_assert(mesh_src->totvert == numVerts);
}
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
cuboid_do(cmd, ctx->object, mesh_src, vertexCos, numVerts);
@ -440,7 +444,7 @@ static void deformVerts(
sphere_do(cmd, ctx->object, mesh_src, vertexCos, numVerts);
}
if (mesh_src != mesh) {
if (!ELEM(mesh_src, NULL, mesh)) {
BKE_id_free(NULL, mesh_src);
}
}