From 073c0b2f3e704de9bf85df7ad37cb8e60e44f818 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Mon, 21 Dec 2020 14:30:55 -0500 Subject: [PATCH] Validate swapchain extent as non-zero --- wgpu-core/src/device/mod.rs | 8 ++++++-- wgpu-core/src/swap_chain.rs | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index e5e61c0f02..0e9f2493c3 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -3847,7 +3847,7 @@ impl Global { fn validate_swap_chain_descriptor( config: &mut hal::window::SwapchainConfig, caps: &hal::window::SurfaceCapabilities, - ) { + ) -> Result<(), swap_chain::CreateSwapChainError> { let width = config.extent.width; let height = config.extent.height; if width < caps.extents.start().width @@ -3870,6 +3870,10 @@ impl Global { ); config.present_mode = hal::window::PresentMode::FIFO; } + if width == 0 || height == 0 { + return Err(swap_chain::CreateSwapChainError::ZeroArea); + } + Ok(()) } tracing::info!("creating swap chain {:?}", desc); @@ -3911,7 +3915,7 @@ impl Global { }); } } - validate_swap_chain_descriptor(&mut config, &caps); + validate_swap_chain_descriptor(&mut config, &caps)?; unsafe { B::get_surface_mut(surface) diff --git a/wgpu-core/src/swap_chain.rs b/wgpu-core/src/swap_chain.rs index b6c7fa7497..e2ece136f6 100644 --- a/wgpu-core/src/swap_chain.rs +++ b/wgpu-core/src/swap_chain.rs @@ -91,6 +91,8 @@ pub enum CreateSwapChainError { InvalidSurface, #[error("`SwapChainOutput` must be dropped before a new `SwapChain` is made")] SwapChainOutputExists, + #[error("Both `SwapChain` width and height must be non-zero. Wait to recreate the `SwapChain` until the window has non-zero area.")] + ZeroArea, #[error("surface does not support the adapter's queue family")] UnsupportedQueueFamily, #[error("requested format {requested:?} is not in list of supported formats: {available:?}")]