Skip to content

Display Indexing Out of Range for `KoToolBox::buttonSize(int)`

Eoin O'Neill requested to merge (removed):buttonSizeCorrection into master

Something about my specific Gnome 3 development environment was causing a crash due to QGuiApplication::screens() indexing throwing an Out of Range assert. Here's the back trace:

#0  0x00007ffff2418f25 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff2402897 in abort () from /usr/lib/libc.so.6
#2  0x00007ffff29778f4 in QMessageLogger::fatal(char const*, ...) const () from /usr/lib/libQt5Core.so.5
#3  0x00007ffff2976d66 in qt_assert_x(char const*, char const*, char const*, int) () from /usr/lib/libQt5Core.so.5
#4  0x00007ffff56eb095 in QList<QScreen*>::at (i=-1, this=0x7fffffffd480)
    at /home/eoin/Source/krita/src/libs/widgets/KoToolBoxLayout_p.h:70
#5  buttonSize (screen=<optimized out>) at /home/eoin/Source/krita/src/libs/widgets/KoToolBox.cpp:50
#6  0x00007ffff5759796 in KoToolBox::addButton (this=0x5555602fdb70, toolAction=0x5555604beae0)
    at /usr/include/qt/QtCore/qcoreapplication.h:116
#7  0x00007ffff575a33f in KoToolBox::KoToolBox (this=0x5555602fdb70)
    at /home/eoin/Source/krita/src/libs/widgets/KoToolBox.cpp:107
#8  0x00007ffff5761f31 in KoToolBoxFactory::createDockWidget (this=0x7fffffffd740)
    at /home/eoin/Source/krita/src/libs/widgets/KoToolBoxFactory.cpp:44
#9  0x00007ffff7087ec2 in KisMainWindow::createDockWidget (this=0x5555578140d0, factory=0x7fffffffd740)
    at /home/eoin/Source/krita/src/libs/ui/KisMainWindow.cpp:2036
#10 0x00007ffff7090858 in KisMainWindow::KisMainWindow (this=<optimized out>, uuid=..., __in_chrg=<optimized out>, 
    __vtt_parm=<optimized out>) at /home/eoin/Source/krita/src/libs/ui/KisMainWindow.cpp:357
#11 0x00007ffff709f482 in KisPart::createMainWindow (
    this=0x7ffff7fc8bd0 <(anonymous namespace)::Q_QGS_s_instance::innerFunction()::holder>, id=...)
    at /home/eoin/Source/krita/src/libs/ui/KisPart.cpp:217
#12 0x00007ffff709f74e in KisPart::startBlankSession (this=<optimized out>) at /usr/include/qt/QtCore/quuid.h:96
#13 0x00007ffff7053562 in KisApplication::start (this=this@entry=0x7fffffffdcd0, args=...)
    at /home/eoin/Source/krita/src/libs/ui/KisApplication.cpp:457
#14 0x0000555555e4e241 in main (argc=<optimized out>, argv=0x7fffffffde38) at /home/eoin/Source/krita/src/krita/main.cc:581

It likely has something to do with my vertical-right oriented display I just set up. I'll do more investigation of this issue, and whether it's a QT or GNOME bug. I figure it's probably a GNOME-Wayland bug for my specific hardware configuration.

For now though, I think preventing any hard crash for simple GUI button size scaling is probably appropriate to avoid edge-case undefined behavior. If buttonSize is called without a valid index, it will simply default to 16 size and print out a warning when run via the terminal. I think printing out a warning is a more elegant fail case in this specific situation, and means we can track future occurrences of these type of bugs.

As an aside, is there actually a way to run krita so that all warnings are treated as asserts (i.e. terminate on first occurrence)?

Merge request reports