From 0dc6bfdd6711e7e8fac8a470015a0ec2642336e7 Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Tue, 13 May 2025 03:10:48 -0400 Subject: [PATCH] Don't raise `AlreadyDestroyed` error on repeated `destroy()` calls (#7686) * Don't raise `AlreadyDestroyed` error on repeated `destroy()` calls * Add changelog entry --- CHANGELOG.md | 1 + wgpu-core/src/resource.rs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6939c18cc..e41b14006d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ Naga now infers the correct binding layout when a resource appears only in an as #### General - Removed `MaintainBase` in favor of using `PollType`. By @waywardmonkeys in [#7508](https://github.com/gfx-rs/wgpu/pull/7508). +- wgpu-core no longer raises an error if `destroy` is called multiple times for a buffer or texture. This only affects the wgpu-core API; the wgpu API already allowed multiple `destroy` calls. By @andyleiserson in [#7686](https://github.com/gfx-rs/wgpu/pull/7686). #### Naga diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 9fc220ac5c..00998b2ef1 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -713,7 +713,8 @@ impl Buffer { let raw = match self.raw.snatch(&mut snatch_guard) { Some(raw) => raw, None => { - return Err(DestroyError::AlreadyDestroyed); + // Per spec, it is valid to call `destroy` multiple times. + return Ok(()); } }; @@ -1189,7 +1190,8 @@ impl Texture { return Ok(()); } None => { - return Err(DestroyError::AlreadyDestroyed); + // Per spec, it is valid to call `destroy` multiple times. + return Ok(()); } }; @@ -1953,8 +1955,6 @@ impl QuerySet { #[derive(Clone, Debug, Error)] #[non_exhaustive] pub enum DestroyError { - #[error("Resource is already destroyed")] - AlreadyDestroyed, #[error(transparent)] InvalidResource(#[from] InvalidResourceError), }