Commit 3bf01de8 authored by Gunnar Sletta's avatar Gunnar Sletta Committed by Qt by Nokia

Clean up dangling pointers in the particle system

When the scenegraph has been invalidated all node
pointers have been deleted. In the image particle case
the material is managed by the nodes and must also
be reset.

Change-Id: I867f0d36a3ea281a58c21f04c937b16b042ef373
Reviewed-by: default avatarKim M. Kalland <kim.kalland@nokia.com>
Reviewed-by: default avatarAlan Alpert <alan.alpert@nokia.com>
parent cbb53d46
......@@ -139,6 +139,12 @@ QQuickCustomParticle::QQuickCustomParticle(QQuickItem* parent)
class QQuickShaderEffectMaterialObject : public QObject, public QQuickShaderEffectMaterial { };
void QQuickCustomParticle::sceneGraphInvalidated()
{
m_nodes.clear();
m_rootNode = 0;
}
QQuickCustomParticle::~QQuickCustomParticle()
{
if (m_material)
......
......@@ -93,6 +93,8 @@ protected:
QQuickShaderEffectNode *buildCustomNodes();
void performPendingResize();
void sceneGraphInvalidated();
private:
void buildData();
......
......@@ -839,6 +839,13 @@ QQmlListProperty<QQuickSprite> QQuickImageParticle::sprites()
return QQmlListProperty<QQuickSprite>(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear);
}
void QQuickImageParticle::sceneGraphInvalidated()
{
m_nodes.clear();
m_rootNode = 0;
m_material = 0;
}
void QQuickImageParticle::setImage(const QUrl &image)
{
if (image.isEmpty()){
......
......@@ -348,6 +348,8 @@ protected:
void prepareNextFrame();
void buildParticleNodes();
void sceneGraphInvalidated();
private slots:
void createEngine(); //### method invoked by sprite list changing (in engine.h) - pretty nasty
......
......@@ -40,6 +40,7 @@
****************************************************************************/
#include "qquickparticlepainter_p.h"
#include <QQuickCanvas>
#include <QDebug>
QT_BEGIN_NAMESPACE
/*!
......@@ -65,10 +66,22 @@ QT_BEGIN_NAMESPACE
*/
QQuickParticlePainter::QQuickParticlePainter(QQuickItem *parent) :
QQuickItem(parent),
m_system(0), m_count(0), m_pleaseReset(true)
m_system(0), m_count(0), m_pleaseReset(true), m_canvas(0)
{
}
void QQuickParticlePainter::itemChange(ItemChange change, const ItemChangeData &data)
{
if (change == QQuickItem::ItemSceneChange) {
if (m_canvas)
disconnect(m_canvas, SIGNAL(sceneGraphInvalidated()), this, SLOT(sceneGraphInvalidated()));
m_canvas = data.canvas;
if (m_canvas)
connect(m_canvas, SIGNAL(sceneGraphInvalidated()), this, SLOT(sceneGraphInvalidated()), Qt::DirectConnection);
}
}
void QQuickParticlePainter::componentComplete()
{
if (!m_system && qobject_cast<QQuickParticleSystem*>(parentItem()))
......
......@@ -76,6 +76,8 @@ public:
return m_groups;
}
void itemChange(ItemChange, const ItemChangeData &);
signals:
void countChanged();
void systemChanged(QQuickParticleSystem* arg);
......@@ -96,6 +98,9 @@ public slots:
void calcSystemOffset(bool resetPending = false);
private slots:
virtual void sceneGraphInvalidated() {}
protected:
/* Reset resets all your internal data structures. But anything attached to a particle should
be in attached data. So reset + reloads should have no visible effect.
......@@ -121,6 +126,8 @@ protected:
QStringList m_groups;
QPointF m_systemOffset;
QQuickCanvas *m_canvas;
private:
QSet<QPair<int,int> > m_pendingCommits;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment