From 8ad5f17d122cdd9c7ba0bb23ae6035e73ecd01de Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 19 Dec 2023 21:16:15 +1300 Subject: Prevent crash when window dimension resizes to zero If an application attempted to change either of the window dimensions to zero, the surface would resize to the new dimensions and cause the window definition in the display server to enter an invalid state, causing the display server to crash the application. This change ensures that the window dimensions are always greater than zero. --- src/window.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/window.rs b/src/window.rs index a7932de..c9bdbcf 100644 --- a/src/window.rs +++ b/src/window.rs @@ -202,7 +202,10 @@ impl Window { } fn dim_to_size(dimensions: Dimensions) -> Size { - Size::Physical( PhysicalSize { width:dimensions.width, height:dimensions.height }) + Size::Physical( PhysicalSize { + width: std::cmp::max(1, dimensions.width), + height: std::cmp::max(1, dimensions.height), + }) } fn dim_to_nonzero_size(dimensions: Dimensions) -> Option<(NonZeroU32, NonZeroU32)> { -- cgit v1.2.3-70-g09d2