Navigation Menu

Skip to content

Commit

Permalink
Clean up dangling pointers in the particle system
Browse files Browse the repository at this point in the history
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: Kim M. Kalland <kim.kalland@nokia.com>
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
  • Loading branch information
Gunnar Sletta authored and Qt by Nokia committed Mar 19, 2012
1 parent cbb53d4 commit 3bf01de
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/quick/particles/qquickcustomparticle.cpp
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/quick/particles/qquickcustomparticle_p.h
Expand Up @@ -93,6 +93,8 @@ public Q_SLOTS:
QQuickShaderEffectNode *buildCustomNodes();
void performPendingResize();

void sceneGraphInvalidated();

private:
void buildData();

Expand Down
7 changes: 7 additions & 0 deletions src/quick/particles/qquickimageparticle.cpp
Expand Up @@ -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()){
Expand Down
2 changes: 2 additions & 0 deletions src/quick/particles/qquickimageparticle_p.h
Expand Up @@ -348,6 +348,8 @@ public slots:
void prepareNextFrame();
void buildParticleNodes();

void sceneGraphInvalidated();

private slots:
void createEngine(); //### method invoked by sprite list changing (in engine.h) - pretty nasty

Expand Down
15 changes: 14 additions & 1 deletion src/quick/particles/qquickparticlepainter.cpp
Expand Up @@ -40,6 +40,7 @@
****************************************************************************/

#include "qquickparticlepainter_p.h"
#include <QQuickCanvas>
#include <QDebug>
QT_BEGIN_NAMESPACE
/*!
Expand All @@ -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()))
Expand Down
7 changes: 7 additions & 0 deletions src/quick/particles/qquickparticlepainter_p.h
Expand Up @@ -76,6 +76,8 @@ class QQuickParticlePainter : public QQuickItem
return m_groups;
}

void itemChange(ItemChange, const ItemChangeData &);

signals:
void countChanged();
void systemChanged(QQuickParticleSystem* arg);
Expand All @@ -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.
Expand All @@ -121,6 +126,8 @@ public slots:
QStringList m_groups;
QPointF m_systemOffset;

QQuickCanvas *m_canvas;

private:
QSet<QPair<int,int> > m_pendingCommits;
};
Expand Down

0 comments on commit 3bf01de

Please sign in to comment.