diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2016-06-03 09:26:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-06-03 09:26:27 +0300 |
commit | e9363483caad3a038237489eea52443b20587bfd (patch) | |
tree | 074b8e5a9fcfe01a350f3530163e5b07d7826fae | |
parent | 8c154d67b2c158722242b3ff14c7c814996c7351 (diff) |
Fix possible uninitialized variable in snapping
Introduced in 0b5a0d84, thanks to Brecht for spotting.
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 62ca4e515a5..4a79310b753 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -992,7 +992,7 @@ static bool snapEditMesh( float imat[4][4]; float timat[3][3]; /* transpose inverse matrix for normals */ float ray_start_local[3], ray_normal_local[3]; - float local_scale, local_depth, len_diff; + float local_scale, local_depth; invert_m4_m4(imat, obmat); transpose_m3_m4(timat, imat); @@ -1089,6 +1089,7 @@ static bool snapEditMesh( * been *inside* boundbox, leading to snap failures (see T38409). * Note also ar might be null (see T38435), in this case we assume ray_start is ok! */ + float len_diff = 0.0f; if (do_ray_start_correction) { /* We *need* a reasonably valid len_diff in this case. * Use BHVTree to find the closest face from ray_start_local. @@ -1098,27 +1099,24 @@ static bool snapEditMesh( nearest.index = -1; nearest.dist_sq = FLT_MAX; /* Compute and store result. */ - BLI_bvhtree_find_nearest( - treedata->tree, ray_start_local, &nearest, treedata->nearest_callback, treedata); - if (nearest.index != -1) { + if (BLI_bvhtree_find_nearest( + treedata->tree, ray_start_local, &nearest, treedata->nearest_callback, treedata) != -1) + { len_diff = sqrtf(nearest.dist_sq); + float ray_org_local[3]; + + copy_v3_v3(ray_org_local, ray_origin); + mul_m4_v3(imat, ray_org_local); + + /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far + * away ray_start values (as returned in case of ortho view3d), see T38358. + */ + len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ + madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local, + len_diff - len_v3v3(ray_start_local, ray_org_local)); + local_depth -= len_diff; } } - float ray_org_local[3]; - - copy_v3_v3(ray_org_local, ray_origin); - mul_m4_v3(imat, ray_org_local); - - /* We pass a temp ray_start, set from object's boundbox, to avoid precision issues with very far - * away ray_start values (as returned in case of ortho view3d), see T38358. - */ - len_diff -= local_scale; /* make temp start point a bit away from bbox hit point. */ - madd_v3_v3v3fl(ray_start_local, ray_org_local, ray_normal_local, - len_diff - len_v3v3(ray_start_local, ray_org_local)); - local_depth -= len_diff; - } - else { - len_diff = 0.0f; } switch (snap_to) { |