From e4ff82569a15a6a7aea7a39b6ea6490de9bfedd0 Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Tue, 9 Jan 2024 15:51:07 -0800 Subject: [PATCH] Make DeviceLostClosure.from_c mutate the closure before dropping it. --- wgpu-core/src/device/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index bb0afedafc5..10e8f401415 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -294,7 +294,7 @@ impl DeviceLostClosure { /// /// - Both pointers must point to `'static` data, as the callback may happen at /// an unspecified time. - pub unsafe fn from_c(closure: DeviceLostClosureC) -> Self { + pub unsafe fn from_c(mut closure: DeviceLostClosureC) -> Self { // Build an inner with the values from closure, ensuring that // inner.called is false. let inner = DeviceLostClosureC { @@ -302,6 +302,10 @@ impl DeviceLostClosure { user_data: closure.user_data, called: false, }; + + // Mark the original closure as called, so we can safely drop it. + closure.called = true; + Self { inner: DeviceLostClosureInner::C { inner }, }