From 27ecd2c30d732d4ccb058157b8d95dc02aebe834 Mon Sep 17 00:00:00 2001 From: Bastien Reboulet Date: Fri, 16 Oct 2020 16:05:45 -0700 Subject: [PATCH] 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: --- ext/qt/qtitem.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/qt/qtitem.cc b/ext/qt/qtitem.cc index 49dafc87eb..7659800b6b 100644 --- a/ext/qt/qtitem.cc +++ b/ext/qt/qtitem.cc @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -87,7 +88,7 @@ public: void run(); private: - QtGLVideoItem *item_; + QPointer 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 ());