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:
@@ -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,34 +637,39 @@ static bool snapDerivedMesh(
|
|||||||
tree_index = 0;
|
tree_index = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (sod->bvh_trees[tree_index] == NULL) {
|
if (tree_index != -1) {
|
||||||
sod->bvh_trees[tree_index] = BLI_memarena_alloc(sctx->cache.mem_arena, sizeof(*treedata));
|
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];
|
||||||
}
|
}
|
||||||
treedata = sod->bvh_trees[tree_index];
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
treedata = &treedata_stack;
|
if (ELEM(snap_to, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_VERTEX)) {
|
||||||
memset(treedata, 0, sizeof(*treedata));
|
treedata = &treedata_stack;
|
||||||
|
memset(treedata, 0, sizeof(*treedata));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
treedata->em_evil = em;
|
if (treedata) {
|
||||||
treedata->em_evil_all = false;
|
treedata->em_evil = em;
|
||||||
switch (snap_to) {
|
treedata->em_evil_all = false;
|
||||||
case SCE_SNAP_MODE_FACE:
|
switch (snap_to) {
|
||||||
bvhtree_from_mesh_looptri(treedata, dm, 0.0f, 4, 6);
|
case SCE_SNAP_MODE_FACE:
|
||||||
break;
|
bvhtree_from_mesh_looptri(treedata, dm, 0.0f, 4, 6);
|
||||||
case SCE_SNAP_MODE_VERTEX:
|
break;
|
||||||
bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6);
|
case SCE_SNAP_MODE_VERTEX:
|
||||||
break;
|
bvhtree_from_mesh_verts(treedata, dm, 0.0f, 2, 6);
|
||||||
|
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.
|
||||||
*/
|
*/
|
||||||
BVHTreeNearest nearest;
|
if (treedata && treedata->tree != NULL) {
|
||||||
|
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,7 +809,9 @@ static bool snapDerivedMesh(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((sctx->flag & SNAP_OBJECT_USE_CACHE) == 0) {
|
if ((sctx->flag & SNAP_OBJECT_USE_CACHE) == 0) {
|
||||||
free_bvhtree_from_mesh(treedata);
|
if (treedata) {
|
||||||
|
free_bvhtree_from_mesh(treedata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user