Qt: Deactivate context if fails to fill context in gst_qt_get_gl_wrapcontext()
We are using the GStreamer QML OpenGL sink and the QtGLVideoItem QQuickItem for displaying video streams from two cameras. In a special setup, when the scene graph was initialized, then the OpenGL context reported an error when trying to create a wrapped context in gst_qt_get_gl_wrapcontext(). That led to that the context was left activated, and when the second QtGLVideoItem handled the scene graph initialized signal, and tried to create a wrapped context, then there was an invalid memory read in the last line here:
gl_api = gst_gl_context_get_current_gl_api (platform, NULL, NULL);
gl_handle = gst_gl_context_get_current_gl_context (platform);
/* see if we already have a current GL context in GStreamer for this thread */
current = gst_gl_context_get_current ();
if (current && current->display == display) {
To prevent that from happening, then the context should be de-activated if the call to gst_gl_context_fill_info() fails, as is done here:
gst_gl_context_activate(*wrap_glcontext, TRUE);
if (!gst_gl_context_fill_info (*wrap_glcontext, &error)) {
GST_ERROR ("failed to retrieve qt context info: %s", error->message);
gst_gl_context_activate(*wrap_glcontext, FALSE);
gst_clear_object (wrap_glcontext);
return FALSE;
}