summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2012-03-07 12:24:30 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-07 12:48:49 +0100
commit5713dde8a1e6a35483134ffe9d986db66b208cf5 (patch)
tree75d03f3495f47a65dac52f7d673dbb7867cce9da
parent83cabda862dced9477d155c84df9440047c856cf (diff)
Fix deadlock in QPropertyAnimation
Commit 1e6514a714c1f55b9cb57d2b8b65bc2305c2e2c6 changed the mutex from recursive to non-recursive, which could introduce dead lock if the animation starts other animation (This is the case in QMainWindow layouts) Change-Id: I1b149b78a802748eb24b5700fffeca0b8555f005 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp1
-rw-r--r--tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp45
2 files changed, 46 insertions, 0 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
index 83ae7bafaa..f7ba49c3cd 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -281,6 +281,7 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State newState,
d->updateMetaProperty();
animToStop = hash.value(key, 0);
hash.insert(key, this);
+ locker.unlock();
// update the default start value
if (oldState == Stopped) {
d->setDefaultStartEndValue(d->targetValue->property(d->propertyName.constData()));
diff --git a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
index 534dec8160..05d1569988 100644
--- a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
+++ b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp
@@ -123,6 +123,7 @@ private slots:
void deletedInUpdateCurrentTime();
void totalDuration();
void zeroLoopCount();
+ void recursiveAnimations();
};
void tst_QPropertyAnimation::initTestCase()
@@ -1237,5 +1238,49 @@ void tst_QPropertyAnimation::zeroLoopCount()
QCOMPARE(finishedSpy.count(), 0);
}
+
+class RecursiveObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal x READ x WRITE setX)
+ Q_PROPERTY(qreal y READ y WRITE setY)
+public:
+ RecursiveObject() : m_x(0), m_y(0) {
+ animation.setTargetObject(this);
+ animation.setPropertyName("y");
+ animation.setDuration(30);
+ }
+ qreal x() const { return m_x; }
+ void setX(qreal x) {
+ m_x = x;
+ animation.setEndValue(x);
+ animation.start();
+ }
+ qreal y() const { return m_y; }
+ void setY(qreal y) { m_y = y; }
+
+ qreal m_x;
+ qreal m_y;
+ QPropertyAnimation animation;
+};
+
+
+void tst_QPropertyAnimation::recursiveAnimations()
+{
+ RecursiveObject o;
+ QPropertyAnimation anim;
+ anim.setTargetObject(&o);
+ anim.setPropertyName("x");
+ anim.setDuration(30);
+
+ anim.setEndValue(4000);
+ anim.start();
+ QTest::qWait(anim.duration() + o.animation.duration());
+ QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QTRY_COMPARE(o.animation.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(o.y(), qreal(4000));
+}
+
+
QTEST_MAIN(tst_QPropertyAnimation)
#include "tst_qpropertyanimation.moc"