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

- allow Users to handle such case
- exception will be thrown instead
This commit is contained in:
Alexander Alekhin 2020-08-15 22:17:33 +00:00
parent 68f527267b
commit 7ec9f52509

View File

@ -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;
}