navigation: add missing sanity checks

On practice a failure happened due to a race condition, the instance
already have been freed, but it could also happen if the instance
would be null.
Instead of crashing this sanity check is a more suitable option,
since with G_DEBUG=fatal-warnings it will crash too.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6475>
This commit is contained in:
Alexander Slobodeniuk 2024-03-28 21:46:11 +01:00 committed by GStreamer Marge Bot
parent 106187cc59
commit b18b3d00b7

View file

@ -93,8 +93,11 @@ gst_navigation_default_init (GstNavigationInterface * iface)
void
gst_navigation_send_event (GstNavigation * navigation, GstStructure * structure)
{
GstNavigationInterface *iface = GST_NAVIGATION_GET_INTERFACE (navigation);
GstNavigationInterface *iface;
g_return_if_fail (GST_IS_NAVIGATION (navigation));
iface = GST_NAVIGATION_GET_INTERFACE (navigation);
if (iface->send_event) {
iface->send_event (navigation, structure);
} else if (iface->send_event_simple) {
@ -116,6 +119,7 @@ void
gst_navigation_send_key_event (GstNavigation * navigation, const char *event,
const char *key)
{
g_return_if_fail (GST_IS_NAVIGATION (navigation));
g_return_if_fail (g_strcmp0 (event, "key-press") == 0 ||
g_strcmp0 (event, "key-release") == 0);
@ -144,6 +148,7 @@ void
gst_navigation_send_mouse_event (GstNavigation * navigation, const char *event,
int button, double x, double y)
{
g_return_if_fail (GST_IS_NAVIGATION (navigation));
g_return_if_fail (g_strcmp0 (event, "mouse-button-press") == 0 ||
g_strcmp0 (event, "mouse-button-release") == 0 ||
g_strcmp0 (event, "mouse-move") == 0);
@ -173,6 +178,8 @@ void
gst_navigation_send_mouse_scroll_event (GstNavigation * navigation,
double x, double y, double delta_x, double delta_y)
{
g_return_if_fail (GST_IS_NAVIGATION (navigation));
gst_navigation_send_event (navigation,
gst_structure_new (GST_NAVIGATION_EVENT_NAME,
"event", G_TYPE_STRING, "mouse-scroll",
@ -193,6 +200,8 @@ void
gst_navigation_send_command (GstNavigation * navigation,
GstNavigationCommand command)
{
g_return_if_fail (GST_IS_NAVIGATION (navigation));
gst_navigation_send_event (navigation,
gst_structure_new (GST_NAVIGATION_EVENT_NAME, "event", G_TYPE_STRING,
"command", "command-code", G_TYPE_UINT, (guint) command, NULL));
@ -209,10 +218,12 @@ gst_navigation_send_command (GstNavigation * navigation,
void
gst_navigation_send_event_simple (GstNavigation * navigation, GstEvent * event)
{
GstNavigationInterface *iface = GST_NAVIGATION_GET_INTERFACE (navigation);
GstNavigationInterface *iface;
g_return_if_fail (GST_IS_NAVIGATION (navigation));
g_return_if_fail (GST_EVENT_TYPE (event) == GST_EVENT_NAVIGATION);
iface = GST_NAVIGATION_GET_INTERFACE (navigation);
if (iface->send_event_simple) {
iface->send_event_simple (navigation, event);
} else if (iface->send_event) {