Skip to content

Commit 22c3ace

Browse files
committed
Fix crash when button_down() / button_up() called re-entrantly
1 parent 9323b17 commit 22c3ace

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

plugin-canvas/src/platform/win32/window.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,27 @@ impl OsWindow {
4646
}
4747

4848
fn button_down(&self, button: MouseButton, position: LogicalPosition) {
49-
let mut buttons_down = self.buttons_down.borrow_mut();
50-
if buttons_down.is_empty() {
51-
unsafe { SetCapture(self.hwnd()); }
52-
}
49+
{
50+
let mut buttons_down = self.buttons_down.borrow_mut();
51+
if buttons_down.is_empty() {
52+
unsafe { SetCapture(self.hwnd()); }
53+
}
5354

54-
buttons_down.insert(button);
55+
buttons_down.insert(button);
56+
}
5557

5658
*self.last_mouse_position.borrow_mut() = position.clone();
5759
self.send_event(Event::MouseButtonDown { button, position });
5860
}
5961

6062
fn button_up(&self, button: MouseButton, position: LogicalPosition) {
61-
let mut buttons_down = self.buttons_down.borrow_mut();
62-
buttons_down.remove(&button);
63+
{
64+
let mut buttons_down = self.buttons_down.borrow_mut();
65+
buttons_down.remove(&button);
6366

64-
if buttons_down.is_empty() {
65-
unsafe { SetCapture(HWND(null_mut())); }
67+
if buttons_down.is_empty() {
68+
unsafe { SetCapture(HWND(null_mut())); }
69+
}
6670
}
6771

6872
*self.last_mouse_position.borrow_mut() = position.clone();

0 commit comments

Comments
 (0)