From 79e6bc2fd63ff06bdbf90da3db88b23bbf6a6b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Tue, 19 Dec 2023 10:48:25 +0100 Subject: [PATCH] Do not assert when preferred{Width|Height} is infinity There's two alternative strategies for fixing this: 1. When fetching the preferred sizes from an item, the number is bounded to a smaller (but still very large) value - not subject to overflow. In practice this will result in the correct layout, but the consequence is a small inconsistency: The preferred size of the layout will be less than infinite despite that one of its items have a preferred size of infinite. 2. Do not bound the fetched preferred sizes from items, but instead let the rest of the code handle infinity. This will result in the correct layout, and also a correct preferred size of the layout. This patch uses the second strategy, by applying a bound when needed. Autotest will be submitted to qtdeclarative, since QGraphicsLayouts are not affected by this. Pick-to: 6.2 Task-number: QTBUG-116577 Change-Id: I49f79d288370bd93831ac9eda623ce4bbf587796 Reviewed-by: Santhosh Kumar (cherry picked from commit 2a95ecf7e81fbdcfad50f8a1dd5c62b120e2ec27) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit c8df6e18df76a1a60986bfa2266e5c00789059bc) (cherry picked from commit ea8aaf2bc364faef58433d1db7aad1ff8b2b7312) --- src/gui/util/qgridlayoutengine.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index f6315adb910..17c1efce566 100644 --- a/src/gui/util/qgridlayoutengine.cpp +++ b/src/gui/util/qgridlayoutengine.cpp @@ -13,6 +13,8 @@ QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; +#define LAYOUTITEMSIZE_MAX (1 << 24) + template static void insertOrRemoveItems(QList &items, int index, int delta) { @@ -194,7 +196,8 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz sumAvailable = targetSize - totalBox.q_minimumSize; if (sumAvailable > 0.0) { - qreal sumDesired = totalBox.q_preferredSize - totalBox.q_minimumSize; + const qreal totalBox_preferredSize = qMin(totalBox.q_preferredSize, qreal(LAYOUTITEMSIZE_MAX)); + qreal sumDesired = totalBox_preferredSize - totalBox.q_minimumSize; for (int i = 0; i < n; ++i) { if (ignore.testBit(start + i)) { @@ -203,7 +206,8 @@ void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSiz } const QGridLayoutBox &box = boxes.at(start + i); - qreal desired = box.q_preferredSize - box.q_minimumSize; + const qreal box_preferredSize = qMin(box.q_preferredSize, qreal(LAYOUTITEMSIZE_MAX)); + qreal desired = box_preferredSize - box.q_minimumSize; factors[i] = growthFactorBelowPreferredSize(desired, sumAvailable, sumDesired); sumFactors += factors[i]; }