diff options
author | Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> | 2014-10-13 10:21:20 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> | 2014-10-13 10:33:10 +0300 |
commit | 732c9f39f08d7867c8e127c84d319ae514d682fd (patch) | |
tree | acb14a3dbe2cb98e154c28b6845b83c687abb752 /src/datavisualizationqml2/abstractdeclarative.cpp | |
parent | 8ff6a5d6d89d80707dc07fc96e22160fa1f8e973 (diff) |
Fix context cleanup
Context was not getting properly cleaned up in cases where
render thread stopped before the cleanup took place.
Now we ensure that required cleanup is done before context
thread terminates.
Change-Id: I1489914dafec928eebb69bac737f6f858ff49432
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualizationqml2/abstractdeclarative.cpp')
-rw-r--r-- | src/datavisualizationqml2/abstractdeclarative.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/src/datavisualizationqml2/abstractdeclarative.cpp b/src/datavisualizationqml2/abstractdeclarative.cpp index 6c6cdb90..7e8de95c 100644 --- a/src/datavisualizationqml2/abstractdeclarative.cpp +++ b/src/datavisualizationqml2/abstractdeclarative.cpp @@ -62,24 +62,7 @@ AbstractDeclarative::AbstractDeclarative(QQuickItem *parent) : AbstractDeclarative::~AbstractDeclarative() { -#ifdef USE_SHARED_CONTEXT - // Context can be in another thread, don't delete it directly in that case - if (m_contextThread && m_contextThread != m_mainThread) { - if (m_context) - m_context->deleteLater(); - m_context = 0; - } else { - delete m_context; - } -#else - if (m_contextThread && m_contextThread != m_mainThread) { - if (m_stateStore) - m_stateStore->deleteLater(); - m_stateStore = 0; - } else { - delete m_stateStore; - } -#endif + destroyContext(); disconnect(this, 0, this, 0); checkWindowList(0); @@ -363,7 +346,6 @@ void AbstractDeclarative::activateOpenGLContext(QQuickWindow *window) m_contextThread = QThread::currentThread(); m_contextWindow = window; m_qtContext = currentContext; - m_context = new QOpenGLContext(); m_context->setFormat(m_qtContext->format()); m_context->setShareContext(m_qtContext); @@ -371,6 +353,10 @@ void AbstractDeclarative::activateOpenGLContext(QQuickWindow *window) m_context->makeCurrent(window); m_controller->initializeOpenGL(); + + // Make sure context gets deleted. + QObject::connect(m_contextThread, &QThread::finished, this, + &AbstractDeclarative::destroyContext, Qt::DirectConnection); } else { m_context->makeCurrent(window); } @@ -392,6 +378,10 @@ void AbstractDeclarative::activateOpenGLContext(QQuickWindow *window) m_stateStore->storeGLState(); m_controller->initializeOpenGL(); + + // Make sure state store gets deleted. + QObject::connect(m_contextThread, &QThread::finished, this, + &AbstractDeclarative::destroyContext, Qt::DirectConnection); } else { m_stateStore->storeGLState(); } @@ -827,4 +817,31 @@ void AbstractDeclarative::windowDestroyed(QObject *obj) windowClearList.remove(win); } +void AbstractDeclarative::destroyContext() +{ +#ifdef USE_SHARED_CONTEXT + // Context can be in another thread, don't delete it directly in that case + if (m_contextThread && m_contextThread != m_mainThread) { + if (m_context) + m_context->deleteLater(); + } else { + delete m_context; + } + m_context = 0; +#else + if (m_contextThread && m_contextThread != m_mainThread) { + if (m_stateStore) + m_stateStore->deleteLater(); + } else { + delete m_stateStore; + } + m_stateStore = 0; +#endif + if (m_contextThread) { + QObject::disconnect(m_contextThread, &QThread::finished, this, + &AbstractDeclarative::destroyContext); + m_contextThread = 0; + } +} + QT_END_NAMESPACE_DATAVISUALIZATION |