Skip to content

Commit b2171dd

Browse files
ed-2100cwfitzgerald
andcommitted
Fix surface drop order. (#6997)
* Fix surface drop order. * Add changes to changelog. * Update SAFETY note. Co-authored-by: Connor Fitzgerald <[email protected]> --------- Co-authored-by: Connor Fitzgerald <[email protected]>
1 parent d06da58 commit b2171dd

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ Bottom level categories:
4040

4141
## Unreleased
4242

43+
### v24.0.3 (2025-03-19)
44+
45+
#### Bug Fixes
46+
- Fix drop order in `Surface`, solving segfaults on exit on some systems. By @ed-2100 in [#6997](https://github.com/gfx-rs/wgpu/pull/6997)
47+
4348
### v24.0.2 (2025-02-26)
4449

4550
#### Bug Fixes

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)