diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index bdb1eb8a82..37b0dfc7f9 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -268,9 +268,14 @@ 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 { + Err(crate::SurfaceError::Other( + "failed to allocate drawable due to metal resource exhaustion", + )) + } + })?; let suf_texture = super::SurfaceTexture { texture: super::Texture {