From da849115b5643120eafc05ce2fc38a034c437eae Mon Sep 17 00:00:00 2001 From: xacrimon Date: Fri, 10 Sep 2021 21:30:30 +0200 Subject: [PATCH] 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 {