Skip to content

Commit cc6ead3

Browse files
geom3trikmicahrj
authored andcommitted
Fixed a bug causing 'already borrowed' error
Fixed a bug where an 'already borrowed' arror would occur when pressing keyboard keys in quick succession. Moving the borrow and borrow_mut of the window state inside the button down/up event seems to fix this.
1 parent b76d416 commit cc6ead3

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/win/window.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ unsafe extern "system" fn wnd_proc(
6969
let mut window = Window { hwnd };
7070
let mut window = crate::Window(&mut window);
7171

72-
let mut mouse_button_counter = window_state.borrow().mouse_button_counter;
73-
7472
match msg {
7573
WM_MOUSEMOVE => {
7674
let x = (lparam & 0xFFFF) as i32;
@@ -92,6 +90,9 @@ unsafe extern "system" fn wnd_proc(
9290
}
9391
WM_LBUTTONDOWN | WM_LBUTTONUP | WM_MBUTTONDOWN | WM_MBUTTONUP |
9492
WM_RBUTTONDOWN | WM_RBUTTONUP | WM_XBUTTONDOWN | WM_XBUTTONUP => {
93+
94+
let mut mouse_button_counter = window_state.borrow().mouse_button_counter;
95+
9596
let button = match msg {
9697
WM_LBUTTONDOWN | WM_LBUTTONUP => Some(MouseButton::Left),
9798
WM_MBUTTONDOWN | WM_MBUTTONUP => Some(MouseButton::Middle),
@@ -126,6 +127,8 @@ unsafe extern "system" fn wnd_proc(
126127
}
127128
};
128129

130+
window_state.borrow_mut().mouse_button_counter = mouse_button_counter;
131+
129132
window_state.borrow_mut()
130133
.handler
131134
.on_event(&mut window, Event::Mouse(event));
@@ -169,7 +172,7 @@ unsafe extern "system" fn wnd_proc(
169172
_ => {}
170173
}
171174

172-
window_state.borrow_mut().mouse_button_counter = mouse_button_counter;
175+
173176
}
174177

175178
return DefWindowProcW(hwnd, msg, wparam, lparam);

0 commit comments

Comments
 (0)