mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-23 02:26:35 +00:00
Catch panics during plugin initialization and log them
This commit is contained in:
parent
9375503296
commit
d98c666bd9
2 changed files with 19 additions and 1 deletions
|
@ -12,6 +12,7 @@ extern crate byte_slice_cast;
|
|||
extern crate glib;
|
||||
#[macro_use]
|
||||
extern crate gst_plugin;
|
||||
#[macro_use]
|
||||
extern crate gstreamer as gst;
|
||||
extern crate gstreamer_audio as gst_audio;
|
||||
extern crate gstreamer_base as gst_base;
|
||||
|
|
|
@ -40,7 +40,24 @@ macro_rules! plugin_define(
|
|||
});
|
||||
|
||||
unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::gst_ffi::GstPlugin) -> $crate::glib_ffi::gboolean {
|
||||
super::$plugin_init(&from_glib_borrow(plugin)).to_glib()
|
||||
use std::panic::{self, AssertUnwindSafe};
|
||||
|
||||
let result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin)).to_glib()));
|
||||
match result {
|
||||
Ok(result) => result,
|
||||
Err(err) => {
|
||||
let cat = $crate::gst::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
|
||||
if let Some(cause) = err.downcast_ref::<&str>() {
|
||||
gst_error!(cat, "Failed to initialize plugin due to panic: {}", cause);
|
||||
} else if let Some(cause) = err.downcast_ref::<String>() {
|
||||
gst_error!(cat, "Failed to initialize plugin due to panic: {}", cause);
|
||||
} else {
|
||||
gst_error!(cat, "Failed to initialize plugin due to panic");
|
||||
}
|
||||
|
||||
$crate::glib_ffi::GFALSE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue