wgpu: Don't create cacheAsBitmap for textures that are too large

This commit is contained in:
Nathan Adams 2023-06-25 22:43:10 +02:00
parent 0ca206ce4f
commit fd4eaef2b6
2 changed files with 12 additions and 0 deletions

View File

@ -9,6 +9,9 @@ pub enum Error {
#[error("Bitmap texture is larger than the rendering device supports")]
TooLarge,
#[error("Bitmap texture has a size of 0 and is invalid")]
InvalidSize,
#[error("Unknown bitmap format")]
UnknownType,

View File

@ -928,6 +928,15 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
width: u32,
height: u32,
) -> Result<BitmapHandle, BitmapError> {
if width == 0 || height == 0 {
return Err(BitmapError::InvalidSize);
}
if width > self.descriptors.limits.max_texture_dimension_2d
|| height > self.descriptors.limits.max_texture_dimension_2d
{
return Err(BitmapError::TooLarge);
}
let extent = wgpu::Extent3d {
width,
height,