Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate swapchain extent as non-zero #1100

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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