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

View file

@ -839,6 +839,10 @@ unsafe extern "system" fn public_window_callback<T>(
use event::WindowEvent::RedrawRequested; use event::WindowEvent::RedrawRequested;
let mut runner = subclass_input.event_loop_runner.runner.borrow_mut(); let mut runner = subclass_input.event_loop_runner.runner.borrow_mut();
if let Some(ref mut runner) = *runner { 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 { match runner.runner_state {
RunnerState::Idle(..) | RunnerState::Idle(..) |
RunnerState::DeferredNewEvents(..) => runner.call_event_handler(Event::WindowEvent { RunnerState::DeferredNewEvents(..) => runner.call_event_handler(Event::WindowEvent {
@ -852,25 +856,10 @@ unsafe extern "system" fn public_window_callback<T>(
}, },
winuser::WM_PAINT => { winuser::WM_PAINT => {
use event::WindowEvent::RedrawRequested; use event::WindowEvent::RedrawRequested;
let event = || Event::WindowEvent { subclass_input.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)), window_id: RootWindowId(WindowId(window)),
event: RedrawRequested, 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) commctrl::DefSubclassProc(window, msg, wparam, lparam)
}, },

View file

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