Handle window resize once per frame

This commit is contained in:
Hanno Braun 2022-10-13 13:03:30 +02:00
parent 085c161ed3
commit 74887df61e

View File

@ -51,6 +51,12 @@ pub fn run(
let mut camera = Camera::new(&Default::default()); let mut camera = Camera::new(&Default::default());
let mut camera_update_once = watcher.is_some(); let mut camera_update_once = watcher.is_some();
// Only handle resize events once every frame. This filters out spurious
// resize events that can lead to wgpu warnings. See this issue for some
// context:
// https://github.com/rust-windowing/winit/issues/2094
let mut new_size = None;
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
trace!("Handling event: {:?}", event); trace!("Handling event: {:?}", event);
@ -147,11 +153,10 @@ pub fn run(
event: WindowEvent::Resized(size), event: WindowEvent::Resized(size),
.. ..
} => { } => {
let size = Size { new_size = Some(Size {
width: size.width, width: size.width,
height: size.height, height: size.height,
}; });
renderer.handle_resize(size);
} }
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::MouseInput { state, button, .. }, event: WindowEvent::MouseInput { state, button, .. },
@ -169,6 +174,9 @@ pub fn run(
if let Some(shape) = &shape { if let Some(shape) = &shape {
camera.update_planes(&shape.aabb); camera.update_planes(&shape.aabb);
} }
if let Some(size) = new_size.take() {
renderer.handle_resize(size);
}
let egui_input = let egui_input =
egui_winit_state.take_egui_input(window.window()); egui_winit_state.take_egui_input(window.window());