Skip to content

Commit

Permalink
Make DeviceLostClosure.from_c mutate the closure before dropping it.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwerth committed Jan 9, 2024
1 parent a24bdba commit e4ff825
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,18 @@ 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 {
callback: closure.callback,
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 },
}
Expand Down

0 comments on commit e4ff825

Please sign in to comment.