Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't panic when reentering wnd_proc due to mouse move or timer #130

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions src/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,26 @@ unsafe extern "system" fn wnd_proc(
if !window_state_ptr.is_null() {
match msg {
WM_MOUSEMOVE => {
let mut window_state = (*window_state_ptr).borrow_mut();
let mut window = window_state.create_window(hwnd);
let mut window = crate::Window::new(&mut window);
if let Ok(mut window_state) = (*window_state_ptr).try_borrow_mut() {
let mut window = window_state.create_window(hwnd);
let mut window = crate::Window::new(&mut window);

let x = (lparam & 0xFFFF) as i16 as i32;
let y = ((lparam >> 16) & 0xFFFF) as i16 as i32;
let x = (lparam & 0xFFFF) as i16 as i32;
let y = ((lparam >> 16) & 0xFFFF) as i16 as i32;

let physical_pos = PhyPoint { x, y };
let logical_pos = physical_pos.to_logical(&window_state.window_info);
let event = Event::Mouse(MouseEvent::CursorMoved {
position: logical_pos,
modifiers: window_state.keyboard_state.get_modifiers_from_mouse_wparam(wparam),
});
let physical_pos = PhyPoint { x, y };
let logical_pos = physical_pos.to_logical(&window_state.window_info);
let event = Event::Mouse(MouseEvent::CursorMoved {
position: logical_pos,
modifiers: window_state
.keyboard_state
.get_modifiers_from_mouse_wparam(wparam),
});

window_state.handler.on_event(&mut window, event);
window_state.handler.on_event(&mut window, event);

return 0;
return 0;
};
}
WM_MOUSEWHEEL => {
let mut window_state = (*window_state_ptr).borrow_mut();
Expand Down Expand Up @@ -223,14 +226,15 @@ unsafe extern "system" fn wnd_proc(
}
}
WM_TIMER => {
let mut window_state = (*window_state_ptr).borrow_mut();
let mut window = window_state.create_window(hwnd);
let mut window = crate::Window::new(&mut window);
if let Ok(mut window_state) = (*window_state_ptr).try_borrow_mut() {
let mut window = window_state.create_window(hwnd);
let mut window = crate::Window::new(&mut window);

if wparam == WIN_FRAME_TIMER {
window_state.handler.on_frame(&mut window);
if wparam == WIN_FRAME_TIMER {
window_state.handler.on_frame(&mut window);
}
return 0;
}
return 0;
}
WM_CLOSE => {
// Make sure to release the borrow before the DefWindowProc call
Expand Down