Fix T75794: Light point gizmo translate jumps

Holding Ctrl while dragging the light point gizmo would use
uninitialized stack memory if the normal had not been
initialized by a surface.

Now holding Ctrl can be used to drag,
even when there is no surface to orient to.
This commit is contained in:
Campbell Barton 2020-04-17 18:48:33 +10:00
parent 774b61189c
commit b6279b7415
Notes: blender-bot 2023-02-14 06:42:53 +01:00
Referenced by issue #75794, Light point gizmo translate mode: Light jumps -431602080 units if translation mode is entered before normal found
1 changed files with 20 additions and 8 deletions

View File

@ -1912,7 +1912,7 @@ static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const
normal_found = true;
}
if (normal_found) {
{
#ifdef USE_RELATIVE_ROTATION
if (is_translate_init && xfd->object_data_len > 1) {
float xform_rot_offset_inv_first[3][3];
@ -1941,16 +1941,26 @@ static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const
item->xform_dist = len_v3v3(item->ob->obmat[3], location_world);
normalize_v3_v3(ob_axis, item->ob->obmat[2]);
/* Scale to avoid adding distance when moving between surfaces. */
float scale = fabsf(dot_v3v3(ob_axis, normal));
item->xform_dist *= scale;
if (normal_found) {
float scale = fabsf(dot_v3v3(ob_axis, normal));
item->xform_dist *= scale;
}
}
float target_normal[3];
copy_v3_v3(target_normal, normal);
if (normal_found) {
copy_v3_v3(target_normal, normal);
}
else {
normalize_v3_v3(target_normal, item->ob->obmat[2]);
}
#ifdef USE_RELATIVE_ROTATION
if (i != 0) {
mul_m3_v3(item->xform_rot_offset, target_normal);
if (normal_found) {
if (i != 0) {
mul_m3_v3(item->xform_rot_offset, target_normal);
}
}
#endif
{
@ -1967,8 +1977,10 @@ static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const
item->ob, item->rot_mat, item->rot_mat[2], location_world);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, item->ob);
}
copy_v3_v3(xfd->prev.normal, normal);
xfd->prev.is_normal_valid = true;
if (normal_found) {
copy_v3_v3(xfd->prev.normal, normal);
xfd->prev.is_normal_valid = true;
}
}
}
else {