Handle zero width or height (#315)

* Avoid resizing when width or height is zero
This commit is contained in:
Max Ammann 2024-08-05 21:01:15 +01:00 committed by GitHub
parent 3dcec8f07b
commit c3201f79e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -156,10 +156,12 @@ impl<ET: 'static + PartialEq + Debug> EventLoop<ET> for WinitEventLoop<ET> {
..
} => window_target.exit(),
WindowEvent::Resized(winit::dpi::PhysicalSize { width, height}) => {
if let Ok(map_context) = map.context_mut() {
let size = PhysicalSize::new(*width, *height).expect("window values should not be zero");
map_context.resize(size, scale_factor);
map.window().request_redraw();
// If height or width is zero, skip this resize event. This happens on Windows when minimizing the window.
if let Some(size) = PhysicalSize::new(*width, *height) {
if let Ok(map_context) = map.context_mut() {
map_context.resize(size, scale_factor);
map.window().request_redraw();
}
}
}
WindowEvent::ScaleFactorChanged { inner_size_writer, scale_factor: new_scale_factor } => {