From e0bce0bd7fc50a1bca916af0d970032783312c41 Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Sat, 22 Jul 2023 00:02:37 +0200 Subject: [PATCH] Add determinant check for minimized windows When the Window is minimized, the transform-determinant can be 0. Add a check to prevent this case. --- scene/main/viewport.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 72676264837d..e5b1ee794ee2 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1347,7 +1347,12 @@ Vector2 Viewport::get_mouse_position() const { // In this case get_screen_transform is not applicable, because it is ambiguous. return gui.last_mouse_pos; } else if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_MOUSE)) { - return get_screen_transform_internal(true).affine_inverse().xform(DisplayServer::get_singleton()->mouse_get_position()); + Transform2D xform = get_screen_transform_internal(true); + if (xform.determinant() == 0) { + // Screen transform can be non-invertible when the Window is minimized. + return Vector2(); + } + return xform.affine_inverse().xform(DisplayServer::get_singleton()->mouse_get_position()); } else { // Fallback to Input for getting mouse position in case of emulated mouse. return get_screen_transform_internal().affine_inverse().xform(Input::get_singleton()->get_mouse_position());