From da849115b5643120eafc05ce2fc38a034c437eae Mon Sep 17 00:00:00 2001 From: xacrimon Date: Fri, 10 Sep 2021 21:30:30 +0200 Subject: [PATCH 1/3] return appropriate error when failing to allocate drawable on metal --- wgpu-hal/src/metal/surface.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index bdb1eb8a82..b10dd01f09 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -268,9 +268,12 @@ impl crate::Surface for super::Surface { ) -> Result>, crate::SurfaceError> { let render_layer = self.render_layer.lock(); let (drawable, texture) = autoreleasepool(|| { - let drawable = render_layer.next_drawable().unwrap(); - (drawable.to_owned(), drawable.texture().to_owned()) - }); + if let Some(drawable) = render_layer.next_drawable() { + Ok((drawable.to_owned(), drawable.texture().to_owned())) + } else { + return Err(crate::SurfaceError::Other("failed to allocate drawable due to metal resource exhaustion")); + } + })?; let suf_texture = super::SurfaceTexture { texture: super::Texture { From a1bfbbbfab26c6600cde0ea30e40fbccea365026 Mon Sep 17 00:00:00 2001 From: xacrimon Date: Fri, 10 Sep 2021 21:44:35 +0200 Subject: [PATCH 2/3] fix lint --- wgpu-hal/src/metal/surface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index b10dd01f09..6cda27a7c7 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -271,7 +271,7 @@ impl crate::Surface for super::Surface { if let Some(drawable) = render_layer.next_drawable() { Ok((drawable.to_owned(), drawable.texture().to_owned())) } else { - return Err(crate::SurfaceError::Other("failed to allocate drawable due to metal resource exhaustion")); + Err(crate::SurfaceError::Other("failed to allocate drawable due to metal resource exhaustion")) } })?; From e013daadc85064212916d4663a4a8d4a460f8438 Mon Sep 17 00:00:00 2001 From: xacrimon Date: Fri, 10 Sep 2021 21:46:21 +0200 Subject: [PATCH 3/3] please rustfmt --- wgpu-hal/src/metal/surface.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index 6cda27a7c7..37b0dfc7f9 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -271,7 +271,9 @@ impl crate::Surface for super::Surface { if let Some(drawable) = render_layer.next_drawable() { Ok((drawable.to_owned(), drawable.texture().to_owned())) } else { - Err(crate::SurfaceError::Other("failed to allocate drawable due to metal resource exhaustion")) + Err(crate::SurfaceError::Other( + "failed to allocate drawable due to metal resource exhaustion", + )) } })?;