Fix infinite loop in QQmlIncubator::forceCompletion
authorAlbert Astals Cid <albert.astals@canonical.com>
Tue, 8 Oct 2013 08:51:03 +0000 (10:51 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 16 Oct 2013 07:09:15 +0000 (09:09 +0200)
commit54b73b8ab53ee41d9c8a855aa9a3da425e0a3f8f
tree81d3b27dc0e0d72e277cec110603b90b6d2651d9
parent29beac9aa1daf9a044dc62e567283779e68b3724
Fix infinite loop in QQmlIncubator::forceCompletion

Without this change I'm getting this backtrace
3  0x4025b9f2 in QQmlIncubatorPrivate::incubate (this=0x18daa78, i=...) at qml/qqmlincubator.cpp:273
4  0x4025c1c2 in QQmlIncubator::forceCompletion (this=0x1527360) at qml/qqmlincubator.cpp:592
5  0x404e1626 in QQuickVisualDataModelPrivate::object (this=this@entry=0x13909f8, group=QQuickListCompositor::Default, index=index@entry=1, asynchronous=asynchronous@entry=false) at items/qquickvisualdatamodel.cpp:900
6  0x404e1f7e in QQuickVisualDataModel::item (this=<optimized out>, index=1, asynchronous=<optimized out>) at items/qquickvisualdatamodel.cpp:968
Note: This is with patched 5.0.x, change QQuickVisualDataModel to QQmlDelegateModel for >= 5.1
      and line numbers may be a bit off

What is happening:
QQmlIncubator::forceCompletion is doing
    while (Loading == status()) {
        while (Loading == status() && !d->waitingFor.isEmpty())
            static_cast<QQmlIncubatorPrivate *>(d->waitingFor.first())->incubate(i);
        if (Loading == status())
            d->incubate(i);
    }
Calling QQmlIncubatorPrivate::incubate on the first item of d->waitingFor

Then, that item is getting to QQmlIncubatorPrivate::incubate and happens that
progress is QQmlIncubatorPrivate::Completed and waitingFor is not empty,
so the only thing that QQmlIncubatorPrivate::incubate ends up doing is
calling a few calls over vmeGuard and returning, that way the inner
waitingFor items never finishe incubating and you end up in an inifite loop inside
        while (Loading == status() && !d->waitingFor.isEmpty())
            static_cast<QQmlIncubatorPrivate *>(d->waitingFor.first())->incubate(i);

This patch basically replaces this loop with a loop that does
        while (QQmlIncubator::Loading == status && !waitingFor.isEmpty())
            static_cast<QQmlIncubatorPrivate *>(waitingFor.first())->forceCompletion(i);

This way we make sure we incubate the waitingFor items of our waitingFor items

Change-Id: I4298efc7ba9d8af624bb138e64b92a40ed4c4dc9
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/qqmlincubator.cpp
src/qml/qml/qqmlincubator_p.h