summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2013-12-16 14:33:27 +0200
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2013-12-17 07:52:33 +0200
commit7465d3de30afd24c1281caa11229c3fb06d18814 (patch)
tree545cddb0574f0a2b37fa40ad30e4b90155ba1cb5
parentdb8f2ba54ffffc30e37adb7986a373b27ec3efa6 (diff)
Fix qml crash when qml launched by external launcher
Task-number: QTRD-2658 Change-Id: Ibf7242f6004a3021fbe1da865545dacb461b8022 Reviewed-by: Pasi Keränen <pasi.keranen@digia.com>
-rw-r--r--src/datavisualizationqml2/declarativerenderer.cpp62
-rw-r--r--src/datavisualizationqml2/declarativerenderer_p.h3
2 files changed, 35 insertions, 30 deletions
diff --git a/src/datavisualizationqml2/declarativerenderer.cpp b/src/datavisualizationqml2/declarativerenderer.cpp
index 419ef74e..b9c80b1a 100644
--- a/src/datavisualizationqml2/declarativerenderer.cpp
+++ b/src/datavisualizationqml2/declarativerenderer.cpp
@@ -33,7 +33,7 @@ DeclarativeRenderer::DeclarativeRenderer(QQuickWindow *window, Abstract3DControl
&DeclarativeRenderer::synchDataToRenderer, Qt::DirectConnection);
connect(m_window, &QQuickWindow::beforeRendering, this,
&DeclarativeRenderer::renderFBO, Qt::DirectConnection);
- connect(m_controller, &Abstract3DController::needRender, m_window,
+ connect(m_controller.data(), &Abstract3DController::needRender, m_window,
&QQuickWindow::update);
}
@@ -45,8 +45,10 @@ DeclarativeRenderer::~DeclarativeRenderer()
void DeclarativeRenderer::synchDataToRenderer()
{
- m_controller->initializeOpenGL();
- m_controller->synchDataToRenderer();
+ if (m_controller) {
+ m_controller->initializeOpenGL();
+ m_controller->synchDataToRenderer();
+ }
}
void DeclarativeRenderer::setDevicePixelRatio(float devicePixelRatio )
@@ -56,38 +58,40 @@ void DeclarativeRenderer::setDevicePixelRatio(float devicePixelRatio )
void DeclarativeRenderer::renderFBO()
{
- QSize size = rect().size().toSize();
- size.setWidth(size.width() * m_devicePixelRatio);
- size.setHeight(size.height() * m_devicePixelRatio);
+ if (m_controller) {
+ QSize size = rect().size().toSize();
+ size.setWidth(size.width() * m_devicePixelRatio);
+ size.setHeight(size.height() * m_devicePixelRatio);
- // Create FBO
- if (!m_fbo) {
- QOpenGLFramebufferObjectFormat format;
- format.setAttachment(QOpenGLFramebufferObject::Depth);
- m_fbo = new QOpenGLFramebufferObject(size, format);
- m_texture = m_window->createTextureFromId(m_fbo->texture(), size);
+ // Create FBO
+ if (!m_fbo) {
+ QOpenGLFramebufferObjectFormat format;
+ format.setAttachment(QOpenGLFramebufferObject::Depth);
+ m_fbo = new QOpenGLFramebufferObject(size, format);
+ m_texture = m_window->createTextureFromId(m_fbo->texture(), size);
- setTexture(m_texture);
+ setTexture(m_texture);
- // Flip texture
- // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2)
- QSize ts = m_texture->textureSize();
- QRectF sourceRect(0, 0, ts.width(), ts.height());
- float tmp = sourceRect.top();
- sourceRect.setTop(sourceRect.bottom());
- sourceRect.setBottom(tmp);
- QSGGeometry *geometry = this->geometry();
- QSGGeometry::updateTexturedRectGeometry(geometry, rect(),
- m_texture->convertToNormalizedSourceRect(sourceRect));
- markDirty(DirtyMaterial);
- }
+ // Flip texture
+ // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2)
+ QSize ts = m_texture->textureSize();
+ QRectF sourceRect(0, 0, ts.width(), ts.height());
+ float tmp = sourceRect.top();
+ sourceRect.setTop(sourceRect.bottom());
+ sourceRect.setBottom(tmp);
+ QSGGeometry *geometry = this->geometry();
+ QSGGeometry::updateTexturedRectGeometry(geometry, rect(),
+ m_texture->convertToNormalizedSourceRect(sourceRect));
+ markDirty(DirtyMaterial);
+ }
- // Call the graph rendering function
- m_fbo->bind();
+ // Call the graph rendering function
+ m_fbo->bind();
- m_controller->render(m_fbo->handle());
+ m_controller->render(m_fbo->handle());
- m_fbo->release();
+ m_fbo->release();
+ }
}
QT_DATAVISUALIZATION_END_NAMESPACE
diff --git a/src/datavisualizationqml2/declarativerenderer_p.h b/src/datavisualizationqml2/declarativerenderer_p.h
index 07d95c2c..75f4f290 100644
--- a/src/datavisualizationqml2/declarativerenderer_p.h
+++ b/src/datavisualizationqml2/declarativerenderer_p.h
@@ -32,6 +32,7 @@
#include "datavisualizationglobal_p.h"
#include <abstract3dcontroller_p.h>
#include <QSGSimpleTextureNode>
+#include <QPointer>
class QOpenGLFramebufferObject;
class QSGTexture;
@@ -57,7 +58,7 @@ private:
QOpenGLFramebufferObject *m_fbo;
QSGTexture *m_texture;
QQuickWindow *m_window;
- Abstract3DController *m_controller;
+ QPointer<Abstract3DController> m_controller;
float m_devicePixelRatio;
};