Bug 457675

Summary: AboutItem freezes with certain font/content combinations
Product: [Frameworks and Libraries] frameworks-kirigami Reporter: Connor Carney <kbugs>
Component: generalAssignee: kdelibs bugs <kdelibs-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: kbugs, nate, notmart
Priority: NOR    
Version: Master   
Target Milestone: Not decided   
Platform: Kubuntu   
OS: Linux   
Latest Commit: Version Fixed In: 5.98
Attachments: qml example
formlayout-freeze
formlayout-freeze-notosans

Description Connor Carney 2022-08-09 12:28:17 UTC
Created attachment 151192 [details]
qml example

SUMMARY
Certain font settings cause Kirigami::AboutItem (and AboutPage) to enter an infinite loop when the homepage URL is the widest thing in the form.

STEPS TO REPRODUCE
1. run the attached file with qmlscene

OBSERVED RESULT
Test application freezes with repeated warnings:

Qt Quick Layouts: Polish loop detected. Aborting after two iterations.
file:///home/connor/Projects/kde/usr/lib/x86_64-linux-gnu/qml/org/kde/kirigami.2/AboutItem.qml:150:5: QML FormLayout (parent or ancestor of QQuickLayoutAttached): Binding loop detected for property "preferredHeight"
file:///home/connor/Projects/kde/usr/lib/x86_64-linux-gnu/qml/org/kde/kirigami.2/AboutItem.qml:150:5: QML FormLayout (parent or ancestor of QQuickLayoutAttached): Binding loop detected for property "preferredHeight"
file:///home/connor/Projects/kde/usr/lib/x86_64-linux-gnu/qml/org/kde/kirigami.2/AboutItem.qml:150:5: QML FormLayout: Binding loop detected for property "implicitHeight"

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Kubuntu 20.04
KDE Plasma Version: 5.24
KDE Frameworks Version: master
Qt Version: 5.15.3
Comment 1 Nate Graham 2022-08-09 19:26:58 UTC
Fixed in Frameworks 5.94; IIRC Kubuntu has 5.92, right?

*** This bug has been marked as a duplicate of bug 447958 ***
Comment 2 Connor Carney 2022-08-09 21:59:54 UTC
This looks similar to that discover bug, but I don't think it's actually a duplicate: that one was working around binding loops with the scroll bar in AboutPage.  My attached example just has a raw AboutItem in a window with no pages or scroll bars in sight.  (It happens with AboutPage too, it's just not necessary to trigger the bug)

In any case, it's not fixed: I tested it against a source build of master, and I can also reproduce it in the current flatpak runtime e.g.

flatpak run --socket=x11 --device=dri --filesystem=home org.kde.Sdk
[📦 org.kde.Sdk ~]$ qmlscene about-page-freeze.qml
Comment 3 Nate Graham 2022-08-10 14:33:35 UTC
Darn.
Comment 4 Connor Carney 2022-08-10 15:00:13 UTC
Created attachment 151226 [details]
formlayout-freeze

I dug into the AboutItem QML and it seems like all that's necessary to recreate the freeze is FormLayout+UrlButton.  I've attached an even more minimal example.
Comment 5 Nate Graham 2022-08-10 17:40:30 UTC
What font and/or font size are necessary to reproduce the bug? That qml file doesn't freeze for me (Wayland, 200% scale, 11pt Noto Sans font).
Comment 6 Connor Carney 2022-08-10 17:57:10 UTC
That QML file explicitly sets Ubuntu 10 pt on the ApplicationWindow, so it shouldn't depend on your font settings, although it does depend on having that font installed.  I normally use kwin-wayland @ 100%, but it also happens in an X session.

It takes some trial and error to find specific combinations of font+size+text that trigger the issue for me, but when I find one it freezes consistently.
Comment 7 Connor Carney 2022-08-10 21:33:25 UTC
Created attachment 151234 [details]
formlayout-freeze-notosans

Here's a case that freezes for me with Noto Sans.

It's interesting that Noto Sans is much less prone to this issue than the Ubuntu font.  I could find cases for Ubuntu by just randomly typing stuff; with Noto Sans I had to actually write a script to find one.
Comment 8 Nate Graham 2022-08-11 17:25:13 UTC
Can confirm the freeze with that file.
Comment 9 Nate Graham 2022-08-16 16:01:11 UTC
Git commit 2676403e803d84e4963fa4e5f3779012e001bf24 by Nate Graham, on behalf of Connor Carney.
Committed on 16/08/2022 at 16:01.
Pushed by ngraham into branch 'master'.

FormLayout: Explicitly round up implicit sizes

The implicit size of an item may not be an integral number of pixels.
GridLayout internally `ceil`s the implicitHeight and implicitWidth 
properties, but not the Layout.* attached properties, so we need to 
call Math.ceil ourselves whenever we set a Layout property based on the 
implicit size.

If a non-integral layout parameter has a fractional part <0.5 then the 
layout engine will end up rounding it down to a pixel-aligned value that 
is not quite large enough to fit the contents (see included test case).

For word-wrapped text, the slightly-too-small size causes the text to
inappropriately wrap. If the implicit size of the wrapped text gets 
rounded differently it causes an infinite loop in the layout.

This changes the behavior of existing clients:  items with non-integral
implicit widths will sometimes lay out  exactly 1 pixel larger. This
won't be an actual problem for existing code. Implicit  sizes already
get rounded up about half the time and layouts should already  be
prepared for that.
FIXED-IN: 5.98

M  +1    -0    autotests/CMakeLists.txt
A  +50   -0    autotests/tst_formlayout.qml  *
M  +2    -2    src/controls/FormLayout.qml

The files marked with a * at the end have a non valid license. Please read: https://community.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://invent.kde.org/frameworks/kirigami/commit/2676403e803d84e4963fa4e5f3779012e001bf24