Bug 459510

Summary: [master] Krita segfaults a couple seconds after undoing group creation in certain cases
Product: [Applications] krita Reporter: tomtomtomreportingin
Component: GeneralAssignee: Dmitry Kazakov <dimula73>
Status: RESOLVED FIXED    
Severity: crash CC: dimula73, eshilina03, halla, lynx.mw+kde
Priority: NOR    
Version: nightly build (please specify the git hash!)   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:

Description tomtomtomreportingin 2022-09-22 06:57:56 UTC
git 890a755

SUMMARY
Krita sometimes segfaults if you undo creation of a group, sometimes after the actual undo or after painting a stroke.

I would guess this has something to do with layer thumbnail generation, due to the delay. In cases that don't crash, the group layer thumbnail doesn't seem to update properly.

STEPS TO REPRODUCE
1. Create a new document.
2. Group layer 1.
3. Undo creation of the group.
4. Paint a stroke.
5. Wait a couple seconds.

OBSERVED RESULT
Segfault.

EXPECTED RESULT
No segfault.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Debian sid
KDE Plasma Version: 5.25.5
KDE Frameworks Version: 5.98.0
Qt Version: 5.12.12 (appimage)
Comment 1 Lynx3d 2022-09-25 23:27:57 UTC
I just had a crash a few seconds after converting image color space for a test, and it did indeed happen in layer thumbnail creation.

The latest upstream commit in my working branch happens to be the same commit.
The backtrace is not terribly useful though...

Application: Krita (krita), signal: Segmentation fault

[KCrash Handler]
#4  0x00007ff79690f300 in  () at /opt/qt515-kde/lib/libQt5Core.so.5
#5  0x00007ff79690f554 in QSortFilterProxyModel::data(QModelIndex const&, int) const () at /opt/qt515-kde/lib/libQt5Core.so.5
#6  0x00007ff7840e6935 in QModelIndex::data(int) const (arole=257, this=0x7ffc50312b10) at /opt/qt515-kde/include/QtCore/qabstractitemmodel.h:460
#7  NodeView::dataChanged(QModelIndex const&, QModelIndex const&, QVector<int> const&) (this=0x55c91c7708c0, topLeft=..., bottomRight=...) at (...)/plugins/dockers/layerdocker/NodeView.cpp:332
#8  0x00007ff7840e47b6 in NodeView::updateNode(QModelIndex const&) (this=<optimized out>, index=...) at (...)/plugins/dockers/layerdocker/NodeView.cpp:157
#9  0x00007ff7840c6d54 in LayerBox::updateDirtyThumbnails() (this=0x55c91c760d50) at (...)/plugins/dockers/layerdocker/LayerBox.cpp:1110
#10 0x00007ff79697d3b8 in  () at /opt/qt515-kde/lib/libQt5Core.so.5
#11 0x00007ff79697d3b8 in  () at /opt/qt515-kde/lib/libQt5Core.so.5
#12 0x00007ff7969813fe in QTimer::timeout(QTimer::QPrivateSignal) () at /opt/qt515-kde/lib/libQt5Core.so.5
#13 0x00007ff796972dbf in QObject::event(QEvent*) () at /opt/qt515-kde/lib/libQt5Core.so.5
#14 0x00007ff7974867a3 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /opt/qt515-kde/lib/libQt5Widgets.so.5
#15 0x00007ff798d0f565 in KisApplication::notify(QObject*, QEvent*) (this=0x7ffc50313450, receiver=0x55c91c7633e0, event=0x7ffc50312fe0) at (...)/libs/ui/KisApplication.cpp:757
#16 0x00007ff79694578a in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /opt/qt515-kde/lib/libQt5Core.so.5
#17 0x00007ff79699dfdb in QTimerInfoList::activateTimers() () at /opt/qt515-kde/lib/libQt5Core.so.5
#18 0x00007ff79699e924 in  () at /opt/qt515-kde/lib/libQt5Core.so.5
#19 0x00007ff793d97d1b in g_main_context_dispatch () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#20 0x00007ff793dec6f8 in  () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#21 0x00007ff793d953c3 in g_main_context_iteration () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#22 0x00007ff79699eca8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /opt/qt515-kde/lib/libQt5Core.so.5
#23 0x00007ff7969440ab in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /opt/qt515-kde/lib/libQt5Core.so.5
#24 0x00007ff79694c644 in QCoreApplication::exec() () at /opt/qt515-kde/lib/libQt5Core.so.5
#25 0x000055c915ab07c1 in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at (...)/krita/main.cc:727
[Inferior 1 (process 59747) detached]
Comment 2 Lynx3d 2022-09-25 23:41:30 UTC
And right again, this time it looks more clear that 9b7318c13298e2fc52b52ac0d760a62152d4a838 is the issue, because it introduced LayerBox::updateDirtyThumbnails():

Application: Krita (krita), signal: Segmentation fault

[KCrash Handler]
#4  0x00007f6bc09084ea in QSortFilterProxyModel::parent(QModelIndex const&) const () at /opt/qt515-kde/lib/libQt5Core.so.5
#5  0x00007f6bc176bb58 in QTreeView::isIndexHidden(QModelIndex const&) const () at /opt/qt515-kde/lib/libQt5Widgets.so.5
#6  0x00007f6bc176a0ac in QTreeView::visualRect(QModelIndex const&) const () at /opt/qt515-kde/lib/libQt5Widgets.so.5
#7  0x00007f6bc16f596e in QAbstractItemView::update(QModelIndex const&) () at /opt/qt515-kde/lib/libQt5Widgets.so.5
#8  0x00007f6bc16fe49a in QAbstractItemView::dataChanged(QModelIndex const&, QModelIndex const&, QVector<int> const&) () at /opt/qt515-kde/lib/libQt5Widgets.so.5
#9  0x00007f6ba95ca8b4 in NodeView::dataChanged(QModelIndex const&, QModelIndex const&, QVector<int> const&) (this=0x560235fc5ac0, topLeft=..., bottomRight=...) at (...)/plugins/dockers/layerdocker/NodeView.cpp:327
#10 0x00007f6ba95c87b6 in NodeView::updateNode(QModelIndex const&) (this=<optimized out>, index=...) at (...)/plugins/dockers/layerdocker/NodeView.cpp:157
#11 0x00007f6ba95aad54 in LayerBox::updateDirtyThumbnails() (this=0x560235bd97d0) at (...)/plugins/dockers/layerdocker/LayerBox.cpp:1110
#12 0x00007f6bc09723b8 in  () at /opt/qt515-kde/lib/libQt5Core.so.5
#13 0x00007f6bc09723b8 in  () at /opt/qt515-kde/lib/libQt5Core.so.5
#14 0x00007f6bc09763fe in QTimer::timeout(QTimer::QPrivateSignal) () at /opt/qt515-kde/lib/libQt5Core.so.5
#15 0x00007f6bc0967dbf in QObject::event(QEvent*) () at /opt/qt515-kde/lib/libQt5Core.so.5
#16 0x00007f6bc147b7a3 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /opt/qt515-kde/lib/libQt5Widgets.so.5
#17 0x00007f6bc2d04565 in KisApplication::notify(QObject*, QEvent*) (this=0x7ffe6389e700, receiver=0x560235fbf470, event=0x7ffe6389e290) at (...)/libs/ui/KisApplication.cpp:757
#18 0x00007f6bc093a78a in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /opt/qt515-kde/lib/libQt5Core.so.5
#19 0x00007f6bc0992fdb in QTimerInfoList::activateTimers() () at /opt/qt515-kde/lib/libQt5Core.so.5
#20 0x00007f6bc0993924 in  () at /opt/qt515-kde/lib/libQt5Core.so.5
#21 0x00007f6bbdd8cd1b in g_main_context_dispatch () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#22 0x00007f6bbdde16f8 in  () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#23 0x00007f6bbdd8a3c3 in g_main_context_iteration () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#24 0x00007f6bc0993ca8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /opt/qt515-kde/lib/libQt5Core.so.5
#25 0x00007f6bc09390ab in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /opt/qt515-kde/lib/libQt5Core.so.5
#26 0x00007f6bc0941644 in QCoreApplication::exec() () at /opt/qt515-kde/lib/libQt5Core.so.5
#27 0x000056022e8ae7c1 in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at (...)/krita/main.cc:727
[Inferior 1 (process 60825) detached]
Comment 3 tomtomtomreportingin 2022-09-26 23:22:45 UTC
You get the same backtrace if you create a group on an empty layer and then close the document.
Comment 4 Lynx3d 2022-09-28 15:51:29 UTC
Git commit eda2d6fbc2ad4949ee96c4ab3f6f10d39a1b422c by Mathias Wein.
Committed on 28/09/2022 at 15:46.
Pushed by mwein into branch 'master'.

Revert "Make sure that thumbnails are generated from exactBounds()"

This reverts commit 9b7318c13298e2fc52b52ac0d760a62152d4a838.

M  +1    -1    libs/image/kis_paint_device.cc
M  +4    -15   plugins/dockers/layerdocker/LayerBox.cpp
M  +1    -5    plugins/dockers/layerdocker/LayerBox.h

https://invent.kde.org/graphics/krita/commit/eda2d6fbc2ad4949ee96c4ab3f6f10d39a1b422c
Comment 5 Tiar 2022-11-05 03:10:35 UTC
Git commit a943b8c708f8a1c921940aea42829c94476f1cbd by Agata Cacko, on behalf of Mathias Wein.
Committed on 05/11/2022 at 03:07.
Pushed by tymond into branch 'krita/5.1'.

Revert "Make sure that thumbnails are generated from exactBounds()"

This reverts commit 9b7318c13298e2fc52b52ac0d760a62152d4a838.
(Note: commit 9b7318c13298e2f is the commit from master.
On krita/5.1, it reverts commit f6389225, which has an incorrect
commit message but is the same commit as the one mentioned).
Related: bug 461436

(cherry picked from commit eda2d6fbc2ad4949ee96c4ab3f6f10d39a1b422c)

M  +1    -1    libs/image/kis_paint_device.cc
M  +4    -15   plugins/dockers/layerdocker/LayerBox.cpp
M  +1    -5    plugins/dockers/layerdocker/LayerBox.h

https://invent.kde.org/graphics/krita/commit/a943b8c708f8a1c921940aea42829c94476f1cbd
Comment 6 Dmitry Kazakov 2022-11-11 13:13:31 UTC
*** Bug 461436 has been marked as a duplicate of this bug. ***
Comment 7 Dmitry Kazakov 2022-11-11 13:14:50 UTC
Git commit 67b8335bf565b71095821590a41f86c272cd663b by Dmitry Kazakov.
Committed on 11/11/2022 at 13:14.
Pushed by dkazakov into branch 'master'.

Fix a crash in thumbnail generation

The dirty layers might have been removed from the image between
the dirty notification and the thumbnails update pass.

M  +2    -1    plugins/dockers/layerdocker/LayerBox.cpp
M  +1    -1    plugins/dockers/layerdocker/LayerBox.h

https://invent.kde.org/graphics/krita/commit/67b8335bf565b71095821590a41f86c272cd663b