Skip to content

Commit 36ccc9f

Browse files
Fix surface drop order. (#6997)
* Fix surface drop order. * Add changes to changelog. * Update SAFETY note. Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com> --------- Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
1 parent 4bb9c39 commit 36ccc9f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ By @brodycj in [#6925](https://github.com/gfx-rs/wgpu/pull/6925).
7878
- Add Flush to GL Queue::submit. By @cwfitzgerald in [#6941](https://github.com/gfx-rs/wgpu/pull/6941).
7979
- Fix `wgpu` not building with `--no-default-features` on when targeting `wasm32-unknown-unknown`. By @wumpf in [#6946](https://github.com/gfx-rs/wgpu/pull/6946).
8080
- Fix `CopyExternalImageDestInfo` not exported on `wgpu`. By @wumpf in [#6962](https://github.com/gfx-rs/wgpu/pull/6962).
81+
- Fix drop order in `Surface`. By @ed-2100 in [#6997](https://github.com/gfx-rs/wgpu/pull/6997)
8182

8283
#### Vulkan
8384

wgpu/src/api/surface.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ static_assertions::assert_impl_all!(SurfaceConfiguration: Send, Sync);
2323
/// [`GPUCanvasContext`](https://gpuweb.github.io/gpuweb/#canvas-context)
2424
/// serves a similar role.
2525
pub struct Surface<'window> {
26-
/// Optionally, keep the source of the handle used for the surface alive.
27-
///
28-
/// This is useful for platforms where the surface is created from a window and the surface
29-
/// would become invalid when the window is dropped.
30-
pub(crate) _handle_source: Option<Box<dyn WindowHandle + 'window>>,
31-
3226
/// Additional surface data returned by [`DynContext::instance_create_surface`].
3327
pub(crate) inner: dispatch::DispatchSurface,
3428

@@ -39,6 +33,14 @@ pub struct Surface<'window> {
3933
// be wrapped in a mutex and since the configuration is only supplied after the surface has
4034
// been created is is additionally wrapped in an option.
4135
pub(crate) config: Mutex<Option<SurfaceConfiguration>>,
36+
37+
/// Optionally, keep the source of the handle used for the surface alive.
38+
///
39+
/// This is useful for platforms where the surface is created from a window and the surface
40+
/// would become invalid when the window is dropped.
41+
///
42+
/// SAFETY: This field must be dropped *after* all other fields to ensure proper cleanup.
43+
pub(crate) _handle_source: Option<Box<dyn WindowHandle + 'window>>,
4244
}
4345

4446
impl Surface<'_> {

0 commit comments

Comments
 (0)