diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index bb0afedafc..10e8f40141 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 }, }