Skip to content

Commit

Permalink
Handle window resize once per frame
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Oct 13, 2022
1 parent 085c161 commit 74887df
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ pub fn run(
let mut camera = Camera::new(&Default::default());
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| {
trace!("Handling event: {:?}", event);

Expand Down Expand Up @@ -147,11 +153,10 @@ pub fn run(
event: WindowEvent::Resized(size),
..
} => {
let size = Size {
new_size = Some(Size {
width: size.width,
height: size.height,
};
renderer.handle_resize(size);
});
}
Event::WindowEvent {
event: WindowEvent::MouseInput { state, button, .. },
Expand All @@ -169,6 +174,9 @@ pub fn run(
if let Some(shape) = &shape {
camera.update_planes(&shape.aabb);
}
if let Some(size) = new_size.take() {
renderer.handle_resize(size);
}

let egui_input =
egui_winit_state.take_egui_input(window.window());
Expand Down

0 comments on commit 74887df

Please sign in to comment.