From 7ec9f52509e81225670a59b55187817057fecdae Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 15 Aug 2020 22:17:33 +0000 Subject: [PATCH] highgui: don't terminate if we can't initialize GTK backend - allow Users to handle such case - exception will be thrown instead --- modules/highgui/src/window_gtk.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_gtk.cpp b/modules/highgui/src/window_gtk.cpp index 76a3760f6a..ad50db30a8 100644 --- a/modules/highgui/src/window_gtk.cpp +++ b/modules/highgui/src/window_gtk.cpp @@ -612,19 +612,33 @@ static std::vector< Ptr > g_windows; CV_IMPL int cvInitSystem( int argc, char** argv ) { static int wasInitialized = 0; + static bool hasError = false; // check initialization status if( !wasInitialized ) { - gtk_init( &argc, &argv ); + if (!gtk_init_check(&argc, &argv)) + { + hasError = true; + wasInitialized = true; + CV_Error(Error::StsError, "Can't initialize GTK backend"); + } + setlocale(LC_NUMERIC,"C"); #ifdef HAVE_OPENGL - gtk_gl_init(&argc, &argv); + if (!gtk_gl_init_check(&argc, &argv)) + { + hasError = true; + wasInitialized = true; + CV_Error(Error::StsError, "Can't initialize GTK-OpenGL backend"); + } #endif wasInitialized = 1; } + if (hasError) + CV_Error(Error::StsError, "GTK backend is not available"); return 0; }