diff options
author | Martin T. H. Sandsmark <martin.sandsmark@kde.org> | 2017-03-12 15:03:56 +0100 |
---|---|---|
committer | Robin Burchell <robin.burchell@crimson.no> | 2017-04-05 20:56:31 +0000 |
commit | 8b255c67b965cda334425d64a0f1fd13ace93584 (patch) | |
tree | e41a9e8326e7fff9d5915111efb7849af57fe5dd | |
parent | 22c39eda8ab316c743d0beac62a9745fd82147f7 (diff) |
QQuickParticleSystem: Fix crash when an Affector dies
A guarded pointer wasn't checked before being de-referenced, that lead
to a crash if an emitter was modified after an affector was deleted, but
before updateCurrentTime() was called.
Change-Id: I6cb605a711319fb77c1e2e87fa9f35427cd7797b
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
3 files changed, 60 insertions, 4 deletions
diff --git a/src/particles/qquickparticlesystem.cpp b/src/particles/qquickparticlesystem.cpp index 99e278238b..6f134f08df 100644 --- a/src/particles/qquickparticlesystem.cpp +++ b/src/particles/qquickparticlesystem.cpp @@ -668,8 +668,11 @@ void QQuickParticleSystem::setPaused(bool arg) { if (m_animation && m_animation->state() != QAbstractAnimation::Stopped) m_paused ? m_animation->pause() : m_animation->resume(); if (!m_paused) { - foreach (QQuickParticlePainter *p, m_painters) - p->update(); + foreach (QQuickParticlePainter *p, m_painters) { + if (p) { + p->update(); + } + } } emit pausedChanged(arg); } @@ -873,8 +876,11 @@ void QQuickParticleSystem::emittersChanged() if (particleCount > bySysIdx.size())//New datum requests haven't updated it bySysIdx.resize(particleCount); - foreach (QQuickParticleAffector *a, m_affectors)//Groups may have changed - a->m_updateIntSet = true; + foreach (QQuickParticleAffector *a, m_affectors) {//Groups may have changed + if (a) { + a->m_updateIntSet = true; + } + } foreach (QQuickParticlePainter *p, m_painters) loadPainter(p); diff --git a/tests/auto/particles/qquickparticlesystem/data/crashaffectors.qml b/tests/auto/particles/qquickparticlesystem/data/crashaffectors.qml new file mode 100644 index 0000000000..de105916a7 --- /dev/null +++ b/tests/auto/particles/qquickparticlesystem/data/crashaffectors.qml @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2017 reMarkable A/S +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Particles 2.0 + +ParticleSystem { + running: false + Affector { Component.onCompleted: destroy() } + Emitter { + Timer { interval: 1; running: true; onTriggered: parent.lifeSpan = 1 } + } +} diff --git a/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp b/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp index 5c82b946e5..5f9db12144 100644 --- a/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp +++ b/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp @@ -42,6 +42,7 @@ public: private slots: void initTestCase(); void test_basic(); + void test_affectorscrash(); }; void tst_qquickparticlesystem::initTestCase() @@ -78,6 +79,12 @@ void tst_qquickparticlesystem::test_basic() delete view; QVERIFY(extremelyFuzzyCompare(stillAlive, 500, 5));//Small simulation variance is permissible. } +void tst_qquickparticlesystem::test_affectorscrash() +{ + QScopedPointer<QQuickView> view (createView(testFileUrl("crashaffectors.qml"), 600)); + + // This should have crashed by now +} QTEST_MAIN(tst_qquickparticlesystem); |