mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
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
This commit is contained in:
parent
bf96e264c9
commit
2b122a20c5
1 changed files with 18 additions and 2 deletions
|
@ -597,9 +597,13 @@ impl App {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn into_context(self: App) -> glutin::WindowedContext<glutin::PossiblyCurrent> {
|
||||||
|
self.windowed_context
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_loop(mut app: App) -> Result<(), Error> {
|
fn main_loop(mut app: App) -> Result<glutin::WindowedContext<glutin::PossiblyCurrent>, Error> {
|
||||||
println!(
|
println!(
|
||||||
"Pixel format of the window's GL context {:?}",
|
"Pixel format of the window's GL context {:?}",
|
||||||
app.windowed_context.get_pixel_format()
|
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.send_event(gst::Event::new_eos().build());
|
||||||
app.pipeline.set_state(gst::State::Null)?;
|
app.pipeline.set_state(gst::State::Null)?;
|
||||||
|
|
||||||
|
Ok(app.into_context())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup(
|
||||||
|
_windowed_context: glutin::WindowedContext<glutin::PossiblyCurrent>,
|
||||||
|
) -> 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn example_main() {
|
fn example_main() {
|
||||||
match App::new().and_then(main_loop) {
|
match App::new().and_then(main_loop).and_then(cleanup) {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => eprintln!("Error! {}", e),
|
Err(e) => eprintln!("Error! {}", e),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue