Validate swapchain extent as non-zero

This commit is contained in:
Connor Fitzgerald
2020-12-21 14:30:55 -05:00
parent b3422257ef
commit 073c0b2f3e
2 changed files with 8 additions and 2 deletions

View File

@@ -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
@@ -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);
@@ -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)

View File

@@ -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:?}")]