Protect against crashes with invalid openglContext()
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 8 Aug 2014 11:00:45 +0000 (13:00 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 8 Aug 2014 18:07:12 +0000 (20:07 +0200)
1) Don't fail the assertion in the animator jobs if we don't have a context
2) Delegate the opengl context check in QQuickWindow::createTextureFromImage
   to the QSGContext

Change-Id: I1b248895dcd6db406f1af8866fd0052dd7564899
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/quick/items/qquickwindow.cpp
src/quick/scenegraph/qsgcontext.cpp
src/quick/util/qquickanimatorjob.cpp

index b987a39..0b82cd3 100644 (file)
@@ -3432,7 +3432,7 @@ QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image) const
 QSGTexture *QQuickWindow::createTextureFromImage(const QImage &image, CreateTextureOptions options) const
 {
     Q_D(const QQuickWindow);
-    if (d->context && d->context->openglContext()) {
+    if (d->context) {
         if (options & TextureCanUseAtlas)
             return d->context->createTexture(image);
         else
index 5bc9199..267c729 100644 (file)
@@ -597,6 +597,8 @@ QSGDepthStencilBufferManager *QSGRenderContext::depthStencilBufferManager()
 
 QSGTexture *QSGRenderContext::createTexture(const QImage &image) const
 {
+    if (!openglContext())
+        return 0;
     QSGTexture *t = m_atlasManager->create(image);
     if (t)
         return t;
index 0bf95a4..e7535be 100644 (file)
@@ -358,7 +358,7 @@ void QQuickXAnimatorJob::updateCurrentTime(int time)
 {
     if (!m_controller)
         return;
-    Q_ASSERT(m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+    Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
 
     m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration);
     m_helper->dx = m_value;
@@ -375,7 +375,7 @@ void QQuickYAnimatorJob::updateCurrentTime(int time)
 {
     if (!m_controller)
         return;
-    Q_ASSERT(m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+    Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
 
     m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration);
     m_helper->dy = m_value;
@@ -433,7 +433,7 @@ void QQuickOpacityAnimatorJob::updateCurrentTime(int time)
 {
     if (!m_controller || !m_opacityNode)
         return;
-    Q_ASSERT(m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+    Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
 
     m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration);
     m_opacityNode->setOpacity(m_value);
@@ -449,7 +449,7 @@ void QQuickScaleAnimatorJob::updateCurrentTime(int time)
 {
     if (!m_controller)
         return;
-    Q_ASSERT(m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+    Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
 
     m_value = m_from + (m_to - m_from) * m_easing.valueForProgress(time / (qreal) m_duration);
     m_helper->scale = m_value;
@@ -469,7 +469,7 @@ void QQuickRotationAnimatorJob::updateCurrentTime(int time)
 {
     if (!m_controller)
         return;
-    Q_ASSERT(m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+    Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
 
     float t =  m_easing.valueForProgress(time / (qreal) m_duration);
     switch (m_direction) {
@@ -549,7 +549,7 @@ void QQuickUniformAnimatorJob::updateCurrentTime(int time)
 {
     if (!m_controller)
         return;
-    Q_ASSERT(m_controller->m_window->openglContext()->thread() == QThread::currentThread());
+    Q_ASSERT(!m_controller->m_window->openglContext() || m_controller->m_window->openglContext()->thread() == QThread::currentThread());
 
     if (!m_node || m_uniformIndex == -1 || m_uniformType == -1)
         return;