Skip to content

Commit

Permalink
[Windows] Prevent overwriting old cursor handle on multiple mouse_mod…
Browse files Browse the repository at this point in the history
…e changes, ensure mouse_mode is set before `cursor_set_shape` is called to restore cursor.

(cherry picked from commit fc1d1c3)
  • Loading branch information
bruvzg authored and akien-mga committed Jun 22, 2020
1 parent f2f11bc commit 1468c0b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 1468c0b

Please sign in to comment.