From f5f675ef6cc6af90a68d956058bef670f6a51204 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 8 Jun 2021 08:39:06 +0000 Subject: [PATCH] highgui(gtk): fix NULL ptr checks --- modules/highgui/src/window_gtk.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index f7570f42c7..a07c3ad5cc 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -1913,17 +1913,19 @@ static gboolean icvOnClose( GtkWidget* widget, GdkEvent* /*event*/, gpointer use static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_data ) { // TODO move this logic to CvImageWidget + // TODO add try-catch wrappers into all callbacks CvWindow* window = (CvWindow*)user_data; + if (!window || !widget || + window->signature != CV_WINDOW_MAGIC_VAL || + window->widget != widget || + !window->on_mouse) + return FALSE; + CvPoint2D32f pt32f = {-1., -1.}; CvPoint pt = {-1,-1}; int cv_event = -1, state = 0, flags = 0; CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); - if( window->signature != CV_WINDOW_MAGIC_VAL || - window->widget != widget || !window->widget || - !window->on_mouse /*|| !image_widget->original_image*/) - return FALSE; - if( event->type == GDK_MOTION_NOTIFY ) { GdkEventMotion* event_motion = (GdkEventMotion*)event; @@ -2016,8 +2018,10 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da pt = cvPointFrom32f( pt32f ); } - if((unsigned)pt.x < (unsigned)(image_widget->original_image->width) && - (unsigned)pt.y < (unsigned)(image_widget->original_image->height) ) + if (!image_widget->original_image/*OpenGL*/ || ( + (unsigned)pt.x < (unsigned)(image_widget->original_image->width) && + (unsigned)pt.y < (unsigned)(image_widget->original_image->height) + )) { flags |= BIT_MAP(state, GDK_SHIFT_MASK, CV_EVENT_FLAG_SHIFTKEY) | BIT_MAP(state, GDK_CONTROL_MASK, CV_EVENT_FLAG_CTRLKEY) |