From 2ee07a2a475e23743800e93ad2bb9f0bb8cc1b8d Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Mon, 7 Sep 2020 16:49:06 -0700 Subject: [PATCH] Fix invalid mip level count check --- wgpu-core/src/device/mod.rs | 5 ++++- wgpu-core/src/resource.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index fb3d908116..78fde0958d 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -515,7 +515,10 @@ impl Device { let usage = conv::map_texture_usage(desc.usage, aspects); let mip_level_count = desc.mip_level_count; - if mip_level_count == 0 && mip_level_count > kind.compute_num_levels() as u32 { + if mip_level_count == 0 + || mip_level_count > MAX_MIP_LEVELS + || mip_level_count > kind.compute_num_levels() as u32 + { return Err(resource::CreateTextureError::InvalidMipLevelCount( mip_level_count, )); diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 322570bab8..78d99bffe9 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -239,7 +239,7 @@ pub enum CreateTextureError { CannotCopyD24Plus, #[error(transparent)] InvalidDimension(#[from] TextureDimensionError), - #[error("texture descriptor mip level count ({0}) must be less than `MAX_MIP_LEVELS`")] + #[error("texture descriptor mip level count ({0}) is invalid")] InvalidMipLevelCount(u32), #[error("Feature {0:?} must be enabled to create a texture of type {1:?}")] MissingFeature(wgt::Features, wgt::TextureFormat),