From eaa3de5045cff86a0f385e858aac3ce7b86b018d Mon Sep 17 00:00:00 2001 From: Andy Leiserson Date: Mon, 22 Jun 2026 17:34:42 -0700 Subject: [PATCH] fix(core): Fix lock order violation in `release_gpu_resources` --- wgpu-core/src/device/resource.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 6b48fff0f..2d6b26a14 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -5654,17 +5654,24 @@ impl Device { // initiate movement into those buckets, and it can do that by calling // "destroy" on all the resources we know about. - // During these iterations, we discard all errors. We don't care! let trackers = self.trackers.lock(); - for buffer in trackers.buffers.used_resources() { - if let Some(buffer) = Weak::upgrade(buffer) { - buffer.destroy(); - } + let buffers = trackers + .buffers + .used_resources() + .flat_map(Weak::upgrade) + .collect::>(); + let textures = trackers + .textures + .used_resources() + .flat_map(Weak::upgrade) + .collect::>(); + drop(trackers); + + for buffer in buffers { + buffer.destroy(); } - for texture in trackers.textures.used_resources() { - if let Some(texture) = Weak::upgrade(texture) { - texture.destroy(); - } + for texture in textures { + texture.destroy(); } }