From 4da46f35ef486a9b9192874221083f62fd5ac1db Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Mon, 5 Feb 2024 16:01:05 +0100 Subject: [PATCH] Avoid a deadlock in Device::lose (#5197) --- wgpu-core/src/device/resource.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 78f7ddee0..4f6f1c14b 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -3362,9 +3362,11 @@ impl Device { // 1) Resolve the GPUDevice device.lost promise. let mut life_lock = self.lock_life(); let closure = life_lock.device_lost_closure.take(); + // It's important to not hold the lock while calling the closure and while calling + // release_gpu_resources which may take the lock again. + drop(life_lock); + if let Some(device_lost_closure) = closure { - // It's important to not hold the lock while calling the closure. - drop(life_lock); device_lost_closure.call(DeviceLostReason::Unknown, message.to_string()); }