Fix T50838: Surface Deform DM use after free issue

Implementd fix suggested by @sergey in T50838.
This commit is contained in:
Luca Rood 2017-03-04 03:16:50 -03:00
parent 6b9d73e8a7
commit 2089a17f7e
Notes: blender-bot 2023-02-14 08:29:54 +01:00
Referenced by issue #50838, Surface Deform Modifier produces inconsistent results when used on multiple objects
1 changed files with 6 additions and 1 deletions

View File

@ -1088,6 +1088,7 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un
SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
DerivedMesh *tdm;
unsigned int tnumpoly;
bool tdm_vert_alloc;
/* Exit function if bind flag is not set (free bind data if any) */
if (!(smd->flags & MOD_SDEF_BIND)) {
@ -1128,12 +1129,16 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un
/* Actual vertex location update starts here */
SDefDeformData data = {.bind_verts = smd->verts,
.mvert = tdm->getVertArray(tdm),
.mvert = DM_get_vert_array(tdm, &tdm_vert_alloc),
.vertexCos = vertexCos};
BLI_task_parallel_range_ex(0, numverts, &data, NULL, 0, deformVert,
numverts > 10000, false);
if (tdm_vert_alloc) {
MEM_freeN((void *)data.mvert);
}
tdm->release(tdm);
}