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.
  • Loading branch information
bruvzg committed Jun 22, 2020
1 parent 6869d5d commit fc1d1c3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ void DisplayServerWindows::_set_mouse_mode_impl(MouseMode p_mode) {
}

if (p_mode == MOUSE_MODE_CAPTURED || p_mode == MOUSE_MODE_HIDDEN) {
hCursor = SetCursor(nullptr);
if (hCursor == nullptr) {
hCursor = SetCursor(nullptr);
} else {
SetCursor(nullptr);
}
} else {
CursorShape c = cursor_shape;
cursor_shape = CURSOR_MAX;
Expand All @@ -117,9 +121,9 @@ void DisplayServerWindows::mouse_set_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);
}

DisplayServer::MouseMode DisplayServerWindows::mouse_get_mode() const {
Expand Down Expand Up @@ -2654,10 +2658,11 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
if (LOWORD(lParam) == HTCLIENT) {
if (windows[window_id].window_has_focus && (mouse_mode == MOUSE_MODE_HIDDEN || mouse_mode == MOUSE_MODE_CAPTURED)) {
//Hide the cursor
if (hCursor == nullptr)
if (hCursor == nullptr) {
hCursor = SetCursor(nullptr);
else
} else {
SetCursor(nullptr);
}
} else {
if (hCursor != nullptr) {
CursorShape c = cursor_shape;
Expand Down

0 comments on commit fc1d1c3

Please sign in to comment.