Synchronously shut down QML rendering threads

This commit is contained in:
Brad Davis 2018-03-28 09:13:46 -07:00
parent aacfe92751
commit 9be162de95

View file

@ -69,6 +69,7 @@ SharedObject::SharedObject() {
_quickWindow->setColor(QColor(255, 255, 255, 0)); _quickWindow->setColor(QColor(255, 255, 255, 0));
_quickWindow->setClearBeforeRendering(true); _quickWindow->setClearBeforeRendering(true);
QObject::connect(qApp, &QCoreApplication::aboutToQuit, this, &SharedObject::onAboutToQuit); QObject::connect(qApp, &QCoreApplication::aboutToQuit, this, &SharedObject::onAboutToQuit);
} }
@ -124,6 +125,7 @@ void SharedObject::setRootItem(QQuickItem* rootItem) {
_renderThread->setObjectName(objectName()); _renderThread->setObjectName(objectName());
_renderThread->start(); _renderThread->start();
// Create event handler for the render thread // Create event handler for the render thread
_renderObject = new RenderEventHandler(this, _renderThread); _renderObject = new RenderEventHandler(this, _renderThread);
QCoreApplication::postEvent(this, new OffscreenEvent(OffscreenEvent::Initialize)); QCoreApplication::postEvent(this, new OffscreenEvent(OffscreenEvent::Initialize));
@ -152,9 +154,16 @@ void SharedObject::destroy() {
QObject::disconnect(_renderControl); QObject::disconnect(_renderControl);
QObject::disconnect(qApp); QObject::disconnect(qApp);
QMutexLocker lock(&_mutex); {
_quit = true; QMutexLocker lock(&_mutex);
QCoreApplication::postEvent(_renderObject, new OffscreenEvent(OffscreenEvent::Quit)); _quit = true;
QCoreApplication::postEvent(_renderObject, new OffscreenEvent(OffscreenEvent::Quit), Qt::HighEventPriority);
}
// Block until the rendering thread has stopped
// FIXME this is undesirable because this is blocking the main thread,
// but I haven't found a reliable way to do this only at application
// shutdown
_renderThread->wait();
} }