From 323fd0037c8d3e016c66fea024b57b11763624ed Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Wed, 20 Jul 2016 10:21:08 +0300 Subject: Fix crash when moving items during asynchronous creation In complicated cases where the model moves rows around while the view is running slow (perhaps during high CPU load), there were cases when Repeater would call movedItem->stackBefore(deleteableItem), but deleteable items can be null, so there was often an error QQuickItem::stackBefore: Cannot stack before 0x0, which must be a sibling and occasionally a crash. Now we check both the callee and the parameter to stackBefore to make sure neither of them are null. Task-number: QTBUG-54859 Change-Id: I45a8b2939c16b9bbe3a802ddd348dc55f51061a7 Reviewed-by: Shawn Rutledge --- src/quick/items/qquickrepeater.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/quick/items/qquickrepeater.cpp b/src/quick/items/qquickrepeater.cpp index 6fc4c0553a..ebf6e9c5cb 100644 --- a/src/quick/items/qquickrepeater.cpp +++ b/src/quick/items/qquickrepeater.cpp @@ -495,8 +495,15 @@ void QQuickRepeater::modelUpdated(const QQmlChangeSet &changeSet, bool reset) QQuickItem *stackBefore = index + items.count() < d->deletables.count() ? d->deletables.at(index + items.count()) : this; - for (int i = index; i < index + items.count(); ++i) - d->deletables.at(i)->stackBefore(stackBefore); + if (stackBefore) { + for (int i = index; i < index + items.count(); ++i) { + if (i < d->deletables.count()) { + QPointer item = d->deletables.at(i); + if (item) + item->stackBefore(stackBefore); + } + } + } } else for (int i = 0; i < insert.count; ++i) { int modelIndex = index + i; ++d->itemCount; -- cgit v1.2.3