aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Wierciński <[email protected]>2024-07-02 17:14:58 +0200
committerPiotr Wierciński <[email protected]>2024-07-17 09:22:14 +0200
commitc9e235a638c991f523cf6250af6ea82ad4a17639 (patch)
tree14f7f414ecaa57686cc4ad48bc6e06fd49ffce8a
parent87723fd948c8666cd327247687db07ae77913d6f (diff)
Fix detecting infinite loops in PolishLoopDetector
Resetting counter too early was causing infinite loop in a function responsible for detecting infinite loops (how ironic). Fix this behavior. Decrease the threshold for detecting infinite loop from 100k to 10k iterations for better responsiveness. Fixes: QTBUG-126474 Pick-to: 6.5 6.7 6.8 Change-Id: Ife45e694d417b1d23fa1294e069ee54eff31c047 Reviewed-by: Jan Arve Sæther <[email protected]>
-rw-r--r--src/quick/items/qquickwindow.cpp54
-rw-r--r--tests/auto/quick/qquickitem/tst_qquickitem.cpp2
2 files changed, 25 insertions, 31 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index bb11eb4d98..a39efbb23a 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -287,37 +287,31 @@ struct PolishLoopDetector
if (itemsToPolish.size() > itemsRemainingBeforeUpdatePolish) {
// Detected potential polish loop.
++numPolishLoopsInSequence;
- if (numPolishLoopsInSequence >= 1000) {
+ if (numPolishLoopsInSequence == 10000) {
+ // We have looped 10,000 times without actually reducing the list of items to
+ // polish, give up for now.
+ // This is not a fix, just a remedy so that the application can be somewhat
+ // responsive.
+ numPolishLoopsInSequence = 0;
+ return true;
+ }
+ if (numPolishLoopsInSequence >= 1000 && numPolishLoopsInSequence < 1005) {
// Start to warn about polish loop after 1000 consecutive polish loops
- if (numPolishLoopsInSequence == 100000) {
- // We have looped 100,000 times without actually reducing the list of items to
- // polish, give up for now.
- // This is not a fix, just a remedy so that the application can be somewhat
- // responsive.
- numPolishLoopsInSequence = 0;
- return true;
- } else if (numPolishLoopsInSequence < 1005) {
- // Show the 5 next items involved in the polish loop.
- // (most likely they will be the same 5 items...)
- QQuickItem *guiltyItem = itemsToPolish.last();
- qmlWarning(item) << "possible QQuickItem::polish() loop";
-
- auto typeAndObjectName = [](QQuickItem *item) {
- QString typeName = QQmlMetaType::prettyTypeName(item);
- QString objName = item->objectName();
- if (!objName.isNull())
- return QLatin1String("%1(%2)").arg(typeName, objName);
- return typeName;
- };
-
- qmlWarning(guiltyItem) << typeAndObjectName(guiltyItem)
- << " called polish() inside updatePolish() of " << typeAndObjectName(item);
-
- if (numPolishLoopsInSequence == 1004)
- // Enough warnings. Reset counter in order to speed things up and re-detect
- // more loops
- numPolishLoopsInSequence = 0;
- }
+ // Show the 5 next items involved in the polish loop.
+ // (most likely they will be the same 5 items...)
+ QQuickItem *guiltyItem = itemsToPolish.last();
+ qmlWarning(item) << "possible QQuickItem::polish() loop";
+
+ auto typeAndObjectName = [](QQuickItem *item) {
+ QString typeName = QQmlMetaType::prettyTypeName(item);
+ QString objName = item->objectName();
+ if (!objName.isNull())
+ return QLatin1String("%1(%2)").arg(typeName, objName);
+ return typeName;
+ };
+
+ qmlWarning(guiltyItem) << typeAndObjectName(guiltyItem)
+ << " called polish() inside updatePolish() of " << typeAndObjectName(item);
}
} else {
numPolishLoopsInSequence = 0;
diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
index 338070b730..2c89744e9e 100644
--- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
@@ -1529,7 +1529,7 @@ void tst_qquickitem::polishLoopDetection_data()
QTest::newRow("test1.100") << PolishItemSpans({ {1, 100} }) << 0;
QTest::newRow("test1.1002") << PolishItemSpans({ {1, 1002} }) << 3;
- QTest::newRow("test1.2020") << PolishItemSpans({ {1, 2020} }) << 10;
+ QTest::newRow("test1.2020") << PolishItemSpans({ {1, 2020} }) << 5;
QTest::newRow("test5.1") << PolishItemSpans({ {5, 1} }) << 0;
QTest::newRow("test5.10") << PolishItemSpans({ {5, 10} }) << 0;