Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / space_view3d / view3d_edit.c
index 8d507ac86c2e09ef6da478ad8946dbb01e2f8a23..0350a67f3d4100bfd1550a0141b36ddc00dd87e4 100644 (file)
@@ -4745,13 +4745,20 @@ void ED_view3d_cursor3d_update(bContext *C, const int mval[2])
                ARegion *ar = CTX_wm_region(C);
                RegionView3D *rv3d = ar->regiondata;
 
-               float co_curr[2], co_prev[2];
+               if (U.uiflag & USER_LOCK_CURSOR_ADJUST) {
 
-               if ((ED_view3d_project_float_global(ar, fp_prev, co_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
-                   (ED_view3d_project_float_global(ar, fp_curr, co_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
-               {
-                       rv3d->ofs_lock[0] += (co_curr[0] - co_prev[0]) / (ar->winx * 0.5f);
-                       rv3d->ofs_lock[1] += (co_curr[1] - co_prev[1]) / (ar->winy * 0.5f);
+                       float co_curr[2], co_prev[2];
+
+                       if ((ED_view3d_project_float_global(ar, fp_prev, co_prev, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
+                               (ED_view3d_project_float_global(ar, fp_curr, co_curr, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
+                       {
+                               rv3d->ofs_lock[0] += (co_curr[0] - co_prev[0]) / (ar->winx * 0.5f);
+                               rv3d->ofs_lock[1] += (co_curr[1] - co_prev[1]) / (ar->winy * 0.5f);
+                       }
+               }
+               else {
+                       /* Cursor may be outside of the view, prevent it getting 'lost', see: T40353 & T45301 */
+                       zero_v2(rv3d->ofs_lock);
                }
        }