highgui: don't terminate if we can't initialize GTK backend

- allow Users to handle such case
- exception will be thrown instead
pull/18105/head
Alexander Alekhin 4 years ago
parent 68f527267b
commit 7ec9f52509
  1. 18
      modules/highgui/src/window_gtk.cpp

@ -612,19 +612,33 @@ static std::vector< Ptr<CvWindow> > 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;
}

Loading…
Cancel
Save