diff options
| author | Antti Määttä <antti.maatta@qt.io> | 2024-06-17 15:14:37 +0300 |
|---|---|---|
| committer | Antti Määttä <antti.maatta@qt.io> | 2024-07-02 15:06:36 +0300 |
| commit | 592235e768cad5dd686a19ff5fe3a90b95307599 (patch) | |
| tree | fd035cb692c854da8c33d65d8c501259a4b713fd | |
| parent | 7c818a8093de6175a37dce03582eea9f9c245874 (diff) | |
QQuickAnimation: Fix setting running property
The setRunning logic can call the setRunning recursively while changing
the property. This might cause missmatch between whether the animation
is actually running and the running property. If we detect recursive
call, make sure that the d->running property matches with the animation
job running status.
Fixes: QTBUG-125224
Change-Id: I2e580d45cea7fd9cb010bc37a366def083b24abb
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit cdf71ef7b62dd92d23a7485a3490527d28097db5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 1ef06979983ab87f2f0b0d15d36c98d4a05deeea)
(cherry picked from commit 5f16dfbe6fecc8315c9752876afc71a96c182d29)
(cherry picked from commit 5e2878df39850f22240151471aa2211d54721702)
Reviewed-by: Antti Määttä <antti.maatta@qt.io>
(cherry picked from commit 1ffc2adeaae09097a9c53a113ff0d9b1062447c0)
| -rw-r--r-- | src/quick/util/qquickanimation.cpp | 5 | ||||
| -rw-r--r-- | tests/auto/quick/qquickanimations/tst_qquickanimations.cpp | 36 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp index 278ec4bd91..69f7c766a3 100644 --- a/src/quick/util/qquickanimation.cpp +++ b/src/quick/util/qquickanimation.cpp @@ -312,6 +312,11 @@ void QQuickAbstractAnimation::setRunning(bool r) // Therefore, the state of d->running will in that case be different than r if we are back in // the root stack frame of the recursive calls to setRunning() emit runningChanged(d->running); + } else if (d->animationInstance) { + // If there was a recursive call, make sure the d->running is set correctly + d->running = d->animationInstance->isRunning(); + } else { + d->running = r; } } diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 95af4a0560..fa724de135 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -117,6 +117,7 @@ private slots: void opacityAnimationFromZero(); void alwaysRunToEndInSequentialAnimationBug(); void cleanupWhenRenderThreadStops(); + void alwaysRunToEndSetFalseRestartBug(); }; #define QTIMED_COMPARE(lhs, rhs) do { \ @@ -2012,6 +2013,41 @@ void tst_qquickanimations::cleanupWhenRenderThreadStops() QVERIFY(QTest::qWaitForWindowExposed(&view)); } +//QTBUG-125224 +void tst_qquickanimations::alwaysRunToEndSetFalseRestartBug() +{ + QQuickRectangle rect; + QQuickAnimationGroup sequential(nullptr); + QQuickPropertyAnimation beginAnim; + QQuickPropertyAnimation endAnim; + + beginAnim.setTargetObject(&rect); + beginAnim.setProperty("x"); + beginAnim.setTo(200); + beginAnim.setDuration(1000); + + endAnim.setTargetObject(&rect); + endAnim.setProperty("x"); + endAnim.setFrom(200); + endAnim.setDuration(1000); + + beginAnim.setGroup(&sequential); + endAnim.setGroup(&sequential); + + sequential.setLoops(-1); + sequential.setAlwaysRunToEnd(true); + + QCOMPARE(sequential.loops(), -1); + QVERIFY(sequential.alwaysRunToEnd()); + sequential.start(); + sequential.stop(); + sequential.setAlwaysRunToEnd(false); + sequential.start(); + QCOMPARE(sequential.isRunning(), true); + sequential.stop(); + QCOMPARE(sequential.isRunning(), false); +} + QTEST_MAIN(tst_qquickanimations) #include "tst_qquickanimations.moc" |
