diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index a77b9622a..9f695d263 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -197,35 +197,17 @@ pub type DeviceLostCallback = Box Self { - let inner = DeviceLostClosureRust { - callback, - consumed: false, - }; + let inner = DeviceLostClosureRust { callback }; Self { inner: DeviceLostClosureInner::Rust { inner }, } @@ -261,18 +240,7 @@ impl DeviceLostClosure { /// /// - Both pointers must point to `'static` data, as the callback may happen at /// an unspecified time. - pub unsafe fn from_c(mut closure: DeviceLostClosureC) -> Self { - // Build an inner with the values from closure, ensuring that - // inner.consumed is false. - let inner = DeviceLostClosureC { - callback: closure.callback, - user_data: closure.user_data, - consumed: false, - }; - - // Mark the original closure as consumed, so we can safely drop it. - closure.consumed = true; - + pub unsafe fn from_c(inner: DeviceLostClosureC) -> Self { Self { inner: DeviceLostClosureInner::C { inner }, } @@ -280,15 +248,9 @@ impl DeviceLostClosure { pub(crate) fn call(self, reason: DeviceLostReason, message: String) { match self.inner { - DeviceLostClosureInner::Rust { mut inner } => { - inner.consumed = true; - - (inner.callback)(reason, message) - } + DeviceLostClosureInner::Rust { inner } => (inner.callback)(reason, message), // SAFETY: the contract of the call to from_c says that this unsafe is sound. - DeviceLostClosureInner::C { mut inner } => unsafe { - inner.consumed = true; - + DeviceLostClosureInner::C { inner } => unsafe { // Ensure message is structured as a null-terminated C string. It only // needs to live as long as the callback invocation. let message = std::ffi::CString::new(message).unwrap();