Keep winit::Window alive until all rendering contexts are destroyed (#37239)

Dropping the window while the rendering contexts are still around causes
a segmentation fault during shutdown. This is a very fragile change. I
added comments to hopes of making regressions less likely.

Testing: I don't think we have a way to write tests for this change
since it requires a wayland system ):
Fixes: https://github.com/servo/servo/issues/36711

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-06-03 21:29:16 +02:00 committed by GitHub
parent c94605b13e
commit 7439fa18d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -49,7 +49,6 @@ use crate::desktop::keyutils::CMD_OR_CONTROL;
use crate::prefs::ServoShellPreferences;
pub struct Window {
winit_window: winit::window::Window,
screen_size: Size2D<u32, DeviceIndependentPixel>,
inner_size: Cell<PhysicalSize<u32>>,
toolbar_height: Cell<Length<f32, DeviceIndependentPixel>>,
@ -72,6 +71,11 @@ pub struct Window {
/// The `RenderingContext` of Servo itself. This is used to render Servo results
/// temporarily until they can be blitted into the egui scene.
rendering_context: Rc<OffscreenRenderingContext>,
// Keep this as the last field of the struct to ensure that the rendering context is
// dropped first.
// (https://github.com/servo/servo/issues/36711)
winit_window: winit::window::Window,
}
impl Window {