Fix crash caused by WM_PAINT getting invoked at inopportune times. (#866)

This commit is contained in:
Osspial 2019-05-16 00:00:30 -04:00 committed by GitHub
parent d5391686ae
commit 6ff1370035
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 18 deletions

View file

@ -21,6 +21,7 @@ fn main() {
Event::NewEvents(StartCause::ResumeTimeReached{..}) => {
*control_flow = ControlFlow::WaitUntil(Instant::now() + Duration::new(1, 0));
println!("\nTimer\n");
_window.set_inner_size(winit::dpi::LogicalSize::new(300.0, 300.0));
},
Event::WindowEvent {
event: WindowEvent::CloseRequested,

View file

@ -839,6 +839,10 @@ unsafe extern "system" fn public_window_callback<T>(
use event::WindowEvent::RedrawRequested;
let mut runner = subclass_input.event_loop_runner.runner.borrow_mut();
if let Some(ref mut runner) = *runner {
// This check makes sure that calls to `request_redraw()` during `EventsCleared`
// handling dispatch `RedrawRequested` immediately after `EventsCleared`, without
// spinning up a new event loop iteration. We do this because that's what the API
// says to do.
match runner.runner_state {
RunnerState::Idle(..) |
RunnerState::DeferredNewEvents(..) => runner.call_event_handler(Event::WindowEvent {
@ -852,25 +856,10 @@ unsafe extern "system" fn public_window_callback<T>(
},
winuser::WM_PAINT => {
use event::WindowEvent::RedrawRequested;
let event = || Event::WindowEvent {
subclass_input.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)),
event: RedrawRequested,
};
let mut send_event = false;
{
let mut runner = subclass_input.event_loop_runner.runner.borrow_mut();
if let Some(ref mut runner) = *runner {
match runner.runner_state {
RunnerState::Idle(..) |
RunnerState::DeferredNewEvents(..) => runner.call_event_handler(event()),
_ => send_event = true
}
}
}
if send_event {
subclass_input.send_event(event());
}
});
commctrl::DefSubclassProc(window, msg, wparam, lparam)
},

View file

@ -730,7 +730,7 @@ unsafe fn init<T: 'static>(
window_flags.set(WindowFlags::MAXIMIZED, attributes.maximized);
let window_state = {
let mut window_state = WindowState::new(
let window_state = WindowState::new(
&attributes,
window_icon,
taskbar_icon,