qmlglsink: fix crash when created/destroyed in quick succession

The crash is caused by a race condition where the render thread
calls a method on the QtGLVideoItem instance that was
previously destroyed by the main thread.
Also, less frequently, QtGLVideoItem::onSceneGraphInitialized
is called when QQuickItem::window is null, also causing a crash.

Fixes #798

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/777>
This commit is contained in:
Bastien Reboulet 2020-10-16 16:05:45 -07:00 committed by GStreamer Merge Bot
parent d885cc0f1a
commit 27ecd2c30d

View file

@ -31,6 +31,7 @@
#include <QtCore/QRunnable>
#include <QtCore/QMutexLocker>
#include <QtCore/QPointer>
#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickWindow>
#include <QtQuick/QSGSimpleTextureNode>
@ -87,7 +88,7 @@ public:
void run();
private:
QtGLVideoItem *item_;
QPointer<QtGLVideoItem> item_;
};
InitializeSceneGraph::InitializeSceneGraph(QtGLVideoItem *item) :
@ -97,7 +98,8 @@ InitializeSceneGraph::InitializeSceneGraph(QtGLVideoItem *item) :
void InitializeSceneGraph::run()
{
item_->onSceneGraphInitialized();
if(item_)
item_->onSceneGraphInitialized();
}
QtGLVideoItem::QtGLVideoItem()
@ -285,6 +287,9 @@ QtGLVideoItemInterface::setBuffer (GstBuffer * buffer)
void
QtGLVideoItem::onSceneGraphInitialized ()
{
if (this->window() == NULL)
return;
GST_DEBUG ("%p scene graph initialization with Qt GL context %p", this,
this->window()->openglContext ());