diff options
author | Sebastian Parborg <darkdefende@gmail.com> | 2019-07-19 03:31:18 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-07-19 03:31:51 +0300 |
commit | 1ae4311902b1daff6a4cacaef1cefc9d37eefcca (patch) | |
tree | 91d8bdf832db87143df18b818075cc57bc1f2e13 /source/blender/editors/space_view3d/view3d_snap.c | |
parent | 48b4d42bce2f94e486af9a51d7b6ec1126b7dc29 (diff) |
Fix T66492: Divide by zero with cursor to selected
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_snap.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_snap.c | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 51dc14f3dff..0103fd0df53 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -634,14 +634,12 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) TransVertStore tvs = {NULL}; TransVert *tv; float bmat[3][3], vec[3], min[3], max[3], centroid[3]; - int count, a; + int count = 0; - count = 0; INIT_MINMAX(min, max); zero_v3(centroid); if (obedit) { - int global_transverts_tot = 0; ViewLayer *view_layer = CTX_data_view_layer(C); uint objects_len = 0; Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data( @@ -662,13 +660,13 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_SKIP_HANDLES); } - global_transverts_tot += tvs.transverts_tot; + count += tvs.transverts_tot; if (tvs.transverts_tot != 0) { Object *obedit_eval = DEG_get_evaluated_object(depsgraph, obedit); copy_m3_m4(bmat, obedit_eval->obmat); tv = tvs.transverts; - for (a = 0; a < tvs.transverts_tot; a++, tv++) { + for (int i = 0; i < tvs.transverts_tot; i++, tv++) { copy_v3_v3(vec, tv->loc); mul_m3_v3(bmat, vec); add_v3_v3(vec, obedit_eval->obmat[3]); @@ -679,14 +677,6 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) ED_transverts_free(&tvs); } MEM_freeN(objects); - - if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEDIAN) { - mul_v3_fl(centroid, 1.0f / (float)global_transverts_tot); - copy_v3_v3(cursor, centroid); - } - else { - mid_v3_v3v3(cursor, min, max); - } } else { Object *obact = CTX_data_active_object(C); @@ -725,18 +715,18 @@ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) } FOREACH_SELECTED_OBJECT_END; } + } - if (count == 0) { - return false; - } + if (count == 0) { + return false; + } - if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEDIAN) { - mul_v3_fl(centroid, 1.0f / (float)count); - copy_v3_v3(cursor, centroid); - } - else { - mid_v3_v3v3(cursor, min, max); - } + if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEDIAN) { + mul_v3_fl(centroid, 1.0f / (float)count); + copy_v3_v3(cursor, centroid); + } + else { + mid_v3_v3v3(cursor, min, max); } return true; } |