diff --git a/examples/imgui-winit/src/main.rs b/examples/imgui-winit/src/main.rs index 068110a..52cacd5 100644 --- a/examples/imgui-winit/src/main.rs +++ b/examples/imgui-winit/src/main.rs @@ -100,13 +100,15 @@ fn main() -> Result<(), Error> { // Resize the window if let Some(size) = input.window_resized() { - // Resize the surface texture - pixels.resize_surface(size.width, size.height); + if size.width > 0 && size.height > 0 { + // Resize the surface texture + pixels.resize_surface(size.width, size.height); - // Resize the world - let LogicalSize { width, height } = size.to_logical(scale_factor); - world.resize(width, height); - pixels.resize_buffer(width, height); + // Resize the world + let LogicalSize { width, height } = size.to_logical(scale_factor); + world.resize(width, height); + pixels.resize_buffer(width, height); + } } // Update internal state and request a redraw diff --git a/src/lib.rs b/src/lib.rs index 72064ec..671f93a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -203,7 +203,14 @@ impl Pixels { /// /// Call this method to change the virtual screen resolution. E.g. when you want your pixel /// buffer to be resized from `640x480` to `800x600`. + /// + /// # Panics + /// + /// Panics when `width` or `height` are 0. pub fn resize_buffer(&mut self, width: u32, height: u32) { + assert!(width > 0); + assert!(height > 0); + // Recreate the backing texture let (scaling_matrix_inverse, texture_extent, texture, scaling_renderer, pixels_buffer_size) = builder::create_backing_texture( @@ -237,8 +244,12 @@ impl Pixels { /// texture for non-integer scaling ratios. /// /// Call this method in response to a resize event from your window manager. The size expected - /// is in physical pixel units. + /// is in physical pixel units. Does nothing when `width` or `height` are 0. pub fn resize_surface(&mut self, width: u32, height: u32) { + if width == 0 || height == 0 { + return; + } + // Update SurfaceTexture dimensions self.surface_size.width = width; self.surface_size.height = height;