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 10, 2024
1 parent a24bdba commit 98c6ec2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Passing an owned value `window` to `Surface` will return a `Surface<'static>`. S
- `BufferMappedRange` trait is now `WasmNotSendSync`, i.e. it is `Send`/`Sync` if not on wasm or `fragile-send-sync-non-atomic-wasm` is enabled. By @wumpf in [#4818](https://github.com/gfx-rs/wgpu/pull/4818)
- Align `wgpu_types::CompositeAlphaMode` serde serialization to spec. By @littledivy in [#4940](https://github.com/gfx-rs/wgpu/pull/4940)
- Fix error message of `ConfigureSurfaceError::TooLarge`. By @Dinnerbone in [#4960](https://github.com/gfx-rs/wgpu/pull/4960)
- Fix dropping of `DeviceLostCallbackC` params. By @bradwerth in [#5032](https://github.com/gfx-rs/wgpu/pull/5032)

#### DX12

Expand Down
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 98c6ec2

Please sign in to comment.