From cc6ead3669991ecbd5950c606e6c1f44ac4c2c03 Mon Sep 17 00:00:00 2001 From: George Atkinson Date: Sat, 19 Dec 2020 21:28:22 +0000 Subject: [PATCH] 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. --- src/win/window.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/win/window.rs b/src/win/window.rs index ec6e270..9738c9a 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -69,8 +69,6 @@ unsafe extern "system" fn wnd_proc( let mut window = Window { hwnd }; let mut window = crate::Window(&mut window); - let mut mouse_button_counter = window_state.borrow().mouse_button_counter; - match msg { WM_MOUSEMOVE => { let x = (lparam & 0xFFFF) as i32; @@ -92,6 +90,9 @@ unsafe extern "system" fn wnd_proc( } WM_LBUTTONDOWN | WM_LBUTTONUP | WM_MBUTTONDOWN | WM_MBUTTONUP | WM_RBUTTONDOWN | WM_RBUTTONUP | WM_XBUTTONDOWN | WM_XBUTTONUP => { + + let mut mouse_button_counter = window_state.borrow().mouse_button_counter; + let button = match msg { WM_LBUTTONDOWN | WM_LBUTTONUP => Some(MouseButton::Left), WM_MBUTTONDOWN | WM_MBUTTONUP => Some(MouseButton::Middle), @@ -126,6 +127,8 @@ unsafe extern "system" fn wnd_proc( } }; + window_state.borrow_mut().mouse_button_counter = mouse_button_counter; + window_state.borrow_mut() .handler .on_event(&mut window, Event::Mouse(event)); @@ -169,7 +172,7 @@ unsafe extern "system" fn wnd_proc( _ => {} } - window_state.borrow_mut().mouse_button_counter = mouse_button_counter; + } return DefWindowProcW(hwnd, msg, wparam, lparam);