From d70b4ab2e58bcfd5e65c1d11a79020bb3e2906c0 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 4 Jan 2022 15:46:07 +0100 Subject: [PATCH] Assert that QQmlDelegateModel's count can't be less than zero I was running into a crash (it didn't reproduce with a minimal example, and I'm still not sure exactly what caused it) related to models and views, and saw that there m_count was negative, which shouldn't be possible. Adding this new assertion allowed me to find the issue in my code. Pick-to: 5.15 6.2 6.3 Change-Id: Ie467e749dbf95799618bd04591e50b0038cf3399 Reviewed-by: Qt CI Bot Reviewed-by: Richard Moe Gustavsen --- src/qmlmodels/qqmldelegatemodel.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index e76d9f4529..e58d4cc18e 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -1746,6 +1746,7 @@ void QQmlDelegateModel::_q_itemsRemoved(int index, int count) return; d->m_count -= count; + Q_ASSERT(d->m_count >= 0); const QList cache = d->m_cache; //Prevents items being deleted in remove loop for (QQmlDelegateModelItem *item : cache)