From 2b122a20c5035d2e8abb1c2dafc9a3cb09e5dc30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 29 Apr 2019 15:43:51 +0300 Subject: [PATCH] examples/glupload: Fix segmentation fault by ensuring the glutin context stays alive longer than the GStreamer GL display Otherwise the GL display might still use a Wayland display that is already freed. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/196 --- examples/src/bin/glupload.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/src/bin/glupload.rs b/examples/src/bin/glupload.rs index 4c5deb409..470c70e13 100644 --- a/examples/src/bin/glupload.rs +++ b/examples/src/bin/glupload.rs @@ -597,9 +597,13 @@ impl App { Ok(()) } + + fn into_context(self: App) -> glutin::WindowedContext { + self.windowed_context + } } -fn main_loop(mut app: App) -> Result<(), Error> { +fn main_loop(mut app: App) -> Result, Error> { println!( "Pixel format of the window's GL context {:?}", app.windowed_context.get_pixel_format() @@ -676,11 +680,23 @@ fn main_loop(mut app: App) -> Result<(), Error> { app.pipeline.send_event(gst::Event::new_eos().build()); app.pipeline.set_state(gst::State::Null)?; + Ok(app.into_context()) +} + +fn cleanup( + _windowed_context: glutin::WindowedContext, +) -> Result<(), failure::Error> { + // To ensure that the context stays alive longer than the pipeline or any reference + // inside GStreamer to the GL context, its display or anything else. See + // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/196 + // + // We might do any window/GL specific cleanup here as needed. + Ok(()) } fn example_main() { - match App::new().and_then(main_loop) { + match App::new().and_then(main_loop).and_then(cleanup) { Ok(r) => r, Err(e) => eprintln!("Error! {}", e), }