Skip to content

Commit

Permalink
Validate swapchain extent as non-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Dec 21, 2020
1 parent b342225 commit 073c0b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3847,7 +3847,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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
Expand All @@ -3870,6 +3870,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
);
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);
Expand Down Expand Up @@ -3911,7 +3915,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
});
}
}
validate_swap_chain_descriptor(&mut config, &caps);
validate_swap_chain_descriptor(&mut config, &caps)?;

unsafe {
B::get_surface_mut(surface)
Expand Down
2 changes: 2 additions & 0 deletions wgpu-core/src/swap_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")]
Expand Down

0 comments on commit 073c0b2

Please sign in to comment.