From 795735d0d9acde21b7c32ec5bc144c623da0fa0e Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Mon, 13 Mar 2023 16:51:32 -0400 Subject: [PATCH] Remove unwraps inside `surface.configure` --- CHANGELOG.md | 1 + wgpu-hal/src/gles/egl.rs | 10 ++++++++-- wgpu-hal/src/gles/web.rs | 10 ++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e49554bd48..94ffedc1d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,6 +122,7 @@ By @teoxoy in [#3534](https://github.com/gfx-rs/wgpu/pull/3534) - [gles] fix: Set FORCE_POINT_SIZE if it is vertex shader with mesh consist of point list. By @REASY in [3440](https://github.com/gfx-rs/wgpu/pull/3440) - [gles] fix: enable `WEBGL_debug_renderer_info` before querying unmasked vendor/renderer to avoid crashing on emscripten in [#3519](https://github.com/gfx-rs/wgpu/pull/3519) +- Remove unwraps inside `surface.configure`. By @cwfitzgerald in [#3585](https://github.com/gfx-rs/wgpu/pull/3585) #### General diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 74e65311e3..b23d5028d0 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -1222,7 +1222,10 @@ impl crate::Surface for Surface { let format_desc = device.shared.describe_texture_format(config.format); let gl = &device.shared.context.lock(); - let renderbuffer = unsafe { gl.create_renderbuffer() }.unwrap(); + let renderbuffer = unsafe { gl.create_renderbuffer() }.map_err(|error| { + log::error!("Internal swapchain renderbuffer creation failed: {error}"); + crate::DeviceError::OutOfMemory + })?; unsafe { gl.bind_renderbuffer(glow::RENDERBUFFER, Some(renderbuffer)) }; unsafe { gl.renderbuffer_storage( @@ -1232,7 +1235,10 @@ impl crate::Surface for Surface { config.extent.height as _, ) }; - let framebuffer = unsafe { gl.create_framebuffer() }.unwrap(); + let framebuffer = unsafe { gl.create_framebuffer() }.map_err(|error| { + log::error!("Internal swapchain framebuffer creation failed: {error}"); + crate::DeviceError::OutOfMemory + })?; unsafe { gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(framebuffer)) }; unsafe { gl.framebuffer_renderbuffer( diff --git a/wgpu-hal/src/gles/web.rs b/wgpu-hal/src/gles/web.rs index 254b6584e0..01c37ec5f9 100644 --- a/wgpu-hal/src/gles/web.rs +++ b/wgpu-hal/src/gles/web.rs @@ -285,7 +285,10 @@ impl crate::Surface for Surface { unsafe { gl.delete_texture(texture) }; } - self.texture = Some(unsafe { gl.create_texture() }.unwrap()); + self.texture = Some(unsafe { gl.create_texture() }.map_err(|error| { + log::error!("Internal swapchain texture creation failed: {error}"); + crate::DeviceError::OutOfMemory + })?); let desc = device.shared.describe_texture_format(config.format); unsafe { gl.bind_texture(glow::TEXTURE_2D, self.texture) }; @@ -313,7 +316,10 @@ impl crate::Surface for Surface { ) }; - let framebuffer = unsafe { gl.create_framebuffer() }.unwrap(); + let framebuffer = unsafe { gl.create_framebuffer() }.map_err(|error| { + log::error!("Internal swapchain framebuffer creation failed: {error}"); + crate::DeviceError::OutOfMemory + })?; unsafe { gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(framebuffer)) }; unsafe { gl.framebuffer_texture_2d(