Correct error in recent snap-context commit

Edges currently don't use a BVH-tree,
but would still create and attempt to free the tree.
This commit is contained in:
Campbell Barton
2016-04-26 23:01:11 +10:00
parent 680b135ec1
commit 96392c33ef

View File

@@ -628,7 +628,7 @@ static bool snapDerivedMesh(
BVHTreeFromMesh *treedata = NULL, treedata_stack;
if (sctx->flag & SNAP_OBJECT_USE_CACHE) {
int tree_index = 0;
int tree_index = -1;
switch (snap_to) {
case SCE_SNAP_MODE_FACE:
tree_index = 1;
@@ -637,16 +637,21 @@ static bool snapDerivedMesh(
tree_index = 0;
break;
}
if (tree_index != -1) {
if (sod->bvh_trees[tree_index] == NULL) {
sod->bvh_trees[tree_index] = BLI_memarena_alloc(sctx->cache.mem_arena, sizeof(*treedata));
}
treedata = sod->bvh_trees[tree_index];
}
}
else {
if (ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX)) {
treedata = &treedata_stack;
memset(treedata, 0, sizeof(*treedata));
}
}
if (treedata) {
treedata->em_evil = em;
treedata->em_evil_all = false;
switch (snap_to) {
@@ -657,14 +662,14 @@ static bool snapDerivedMesh(
bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6);
break;
}
}
if (need_ray_start_correction_init) {
/* We *need* a reasonably valid len_diff in this case.
* Use BHVTree to find the closest face from ray_start_local.
*/
if (treedata && treedata->tree != NULL) {
BVHTreeNearest nearest;
if (treedata->tree != NULL) {
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
/* Compute and store result. */
@@ -804,9 +809,11 @@ static bool snapDerivedMesh(
}
if ((sctx->flag & SNAP_OBJECT_USE_CACHE) == 0) {
if (treedata) {
free_bvhtree_from_mesh(treedata);
}
}
}
return retval;
}