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>
This commit is contained in:
ed-2100andConnor Fitzgerald authored and Connor Fitzgerald committed 2025-03-19 13:22:16 -04:00
1 parent d06da58b66
commit b2171dd1a4
2 files changed
+13 -6

No files matched your search

+5
View File
@@ -40,6 +40,11 @@ Bottom level categories:
## Unreleased
### v24.0.3 (2025-03-19)
#### Bug Fixes
- 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)
### v24.0.2 (2025-02-26)
#### Bug Fixes
+8 -6
View File
@@ -23,12 +23,6 @@ static_assertions::assert_impl_all!(SurfaceConfiguration: Send, Sync);
/// [`GPUCanvasContext`](https://gpuweb.github.io/gpuweb/#canvas-context)
/// serves a similar role.
pub struct Surface<'window> {
/// Optionally, keep the source of the handle used for the surface alive.
///
/// This is useful for platforms where the surface is created from a window and the surface
/// would become invalid when the window is dropped.
pub(crate) _handle_source: Option<Box<dyn WindowHandle + 'window>>,
/// Additional surface data returned by [`DynContext::instance_create_surface`].
pub(crate) inner: dispatch::DispatchSurface,
@@ -39,6 +33,14 @@ pub struct Surface<'window> {
// be wrapped in a mutex and since the configuration is only supplied after the surface has
// been created is is additionally wrapped in an option.
pub(crate) config: Mutex<Option<SurfaceConfiguration>>,
/// Optionally, keep the source of the handle used for the surface alive.
///
/// This is useful for platforms where the surface is created from a window and the surface
/// would become invalid when the window is dropped.
///
/// SAFETY: This field must be dropped *after* all other fields to ensure proper cleanup.
pub(crate) _handle_source: Option<Box<dyn WindowHandle + 'window>>,
}
impl Surface<'_> {