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