From 1468c0b4d4592406502c7e4eaa2121f1d0a7e5f6 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 22 Jun 2020 13:05:18 +0300 Subject: [PATCH] [Windows] Prevent overwriting old cursor handle on multiple mouse_mode changes, ensure mouse_mode is set before `cursor_set_shape` is called to restore cursor. (cherry picked from commit fc1d1c3557de3339d18df2639e12edca33a774a5) --- platform/windows/os_windows.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index e51b0569f52..7560eddd630 100755 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1186,10 +1186,11 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (LOWORD(lParam) == HTCLIENT) { if (window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED)) { //Hide the cursor - if (hCursor == NULL) + if (hCursor == NULL) { hCursor = SetCursor(NULL); - else + } else { SetCursor(NULL); + } } else { if (hCursor != NULL) { CursorShape c = cursor_shape; @@ -1864,9 +1865,9 @@ void OS_Windows::set_mouse_mode(MouseMode p_mode) { if (mouse_mode == p_mode) return; - _set_mouse_mode_impl(p_mode); - mouse_mode = p_mode; + + _set_mouse_mode_impl(p_mode); } void OS_Windows::_set_mouse_mode_impl(MouseMode p_mode) { @@ -1890,7 +1891,11 @@ void OS_Windows::_set_mouse_mode_impl(MouseMode p_mode) { } if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_HIDDEN) { - hCursor = SetCursor(NULL); + if (hCursor == NULL) { + hCursor = SetCursor(NULL); + } else { + SetCursor(NULL); + } } else { CursorShape c = cursor_shape; cursor_shape = CURSOR_MAX;