From 26624c04e0e3b5e33ec32f755a949cdd4d0c230e Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:30:32 +0200 Subject: [PATCH] add `SurfaceError::TextureDestroyed` --- wgpu-core/src/present.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/wgpu-core/src/present.rs b/wgpu-core/src/present.rs index d03a72bae..6995cbf9f 100644 --- a/wgpu-core/src/present.rs +++ b/wgpu-core/src/present.rs @@ -43,6 +43,8 @@ pub enum SurfaceError { Device(#[from] DeviceError), #[error("Surface image is already acquired")] AlreadyAcquired, + #[error("Texture has been destroyed")] + TextureDestroyed, #[error("Acquired frame is still referenced")] StillReferenced, } @@ -271,15 +273,13 @@ impl Global { .take() .ok_or(SurfaceError::AlreadyAcquired)?; - let result = match texture - .inner - .snatch(&mut device.snatchable_lock.write()) - .unwrap() - { - resource::TextureInner::Surface { raw } => unsafe { + let result = match texture.inner.snatch(&mut device.snatchable_lock.write()) { + None => return Err(SurfaceError::TextureDestroyed), + Some(resource::TextureInner::Surface { raw }) => { let raw_surface = surface.raw(device.backend()).unwrap(); - queue.raw().present(raw_surface, raw) - }, + let raw_queue = queue.raw(); + unsafe { raw_queue.present(raw_surface, raw) } + } _ => unreachable!(), }; @@ -323,12 +323,9 @@ impl Global { .take() .ok_or(SurfaceError::AlreadyAcquired)?; - match texture - .inner - .snatch(&mut device.snatchable_lock.write()) - .unwrap() - { - resource::TextureInner::Surface { raw } => { + match texture.inner.snatch(&mut device.snatchable_lock.write()) { + None => return Err(SurfaceError::TextureDestroyed), + Some(resource::TextureInner::Surface { raw }) => { let raw_surface = surface.raw(device.backend()).unwrap(); unsafe { raw_surface.discard_texture(raw) }; }