qmlglsink: fix crash when created/destroyed in quick succession
authorBastien Reboulet <bastien.reboulet@gmail.com>
Fri, 16 Oct 2020 23:05:45 +0000 (16:05 -0700)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 20 Oct 2020 18:12:20 +0000 (18:12 +0000)
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>

ext/qt/qtitem.cc

index 49dafc8..7659800 100644 (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 ());