Bug 411124

Summary: Merge Group on invisible group layer crashes krita
Product: [Applications] krita Reporter: Nicholas Killewald <captainspam>
Component: Layer StackAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: halla, khoohaoyit31
Priority: NOR    
Version: 4.2.5   
Target Milestone: ---   
Platform: Kubuntu   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Nicholas Killewald 2019-08-21 03:33:40 UTC
If a group layer with any sublayers is set to invisible and "Merge Group" is selected from the right-click menu on that group in the layers docker, Krita crashes.

STEPS TO REPRODUCE
1. Create a new image
2. Create a group layer and add at least one layer to it (or right-click an existing layer -> Group -> Quick Group)
3. Make that group layer invisible by clicking its eye icon in the layers docker
4. Right-click that group layer and click "Merge Group"

OBSERVED RESULT

Krita crashes immediately.

EXPECTED RESULT

Either the group should be merged and remain invisible, a message should appear saying this action makes little sense, or "Merge Group" should be greyed out if the user shouldn't be doing that in that situation in the first place.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Kernel 4.15.0-58-generic (via Ubuntu)
(available in About System)
KDE Plasma Version: 5.12.8
KDE Frameworks Version: 5.47.0
Qt Version: 5.9.5

ADDITIONAL INFORMATION

With some additional testing, I've seen this NOT crash a few times with the exact same inputs.  I'd put it at around a 95% crash rate, though.
Comment 1 Halla Rempt 2019-08-21 06:53:18 UTC
Thank you for the report. I can confirm the crash:

ASSERT: "!isEmpty()" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h, line 347

Thread 1 (Thread 0x7fc4ea34e800 (LWP 27362)):
[KCrash Handler]
#6  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#7  0x00007fc4ef8af535 in __GI_abort () at abort.c:79
#8  0x00007fc4efcf69a7 in QMessageLogger::fatal(char const*, ...) const () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#9  0x00007fc4efcf5e29 in qt_assert(char const*, char const*, int) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#10 0x00007fc4f134e10a in QList<KisSharedPtr<KisNode> >::first (this=this@entry=0x7fff184b73d0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:347
#11 0x00007fc4f13475e0 in KisLayerUtils::mergeMultipleLayersImpl (image=..., mergedNodes=..., putAfter=..., flattenSingleLayer=flattenSingleLayer@entry=true, actionName=..., cleanupNodes=cleanupNodes@entry=true, layerName=...) at /home/boud/dev/krita/libs/image/kis_layer_utils.cpp:1289
#12 0x00007fc4f1347d9c in KisLayerUtils::flattenLayer (image=..., layer=...) at /home/boud/dev/krita/libs/image/kis_layer_utils.cpp:1462
#13 0x00007fc4f1318320 in KisImage::flattenLayer (this=<optimized out>, layer=...) at /home/boud/dev/krita/libs/image/kis_image.cc:1287
#14 0x00007fc4f2309159 in tryFlattenGroupLayer (currentNode=..., image=...) at /home/boud/dev/krita/libs/ui/kis_layer_manager.cc:784
#15 0x00007fc4f230cdd9 in KisLayerManager::mergeLayer (this=0x55a1888990f0) at /home/boud/dev/krita/libs/ui/kis_layer_manager.cc:808
#16 0x00007fc4f272cf75 in KisLayerManager::qt_static_metacall (_o=<optimized out>, _c=<optimized out>, _id=<optimized out>, _a=0x7fff184b7690) at /home/boud/dev/b-krita/libs/ui/kritaui_autogen/EWIEGA46WW/moc_kis_layer_manager.cpp:173
#17 0x00007fc4eff0d426 in QMetaObject::activate(QObject*, int, int, void**) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#18 0x00007fc4f08a2fe2 in QAction::triggered(bool) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#19 0x00007fc4f08a55f0 in QAction::activate(QAction::ActionEvent) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#20 0x00007fc4f0a17f3c in ?? () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#21 0x00007fc4f0a1f460 in ?? () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#22 0x00007fc4f0a203ab in QMenu::mouseReleaseEvent(QMouseEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#23 0x00007fc4f08e8b58 in QWidget::event(QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#24 0x00007fc4f0a2284b in QMenu::event(QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#25 0x00007fc4f08a9551 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#26 0x00007fc4f08b0b77 in QApplication::notify(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#27 0x00007fc4f260f097 in KisApplication::notify (this=<optimized out>, receiver=0x7fff184b8710, event=0x7fff184b7dc0) at /home/boud/dev/krita/libs/ui/KisApplication.cpp:653
#28 0x00007fc4efee38e9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#29 0x00007fc4f08afebf in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool, bool) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#30 0x00007fc4f0903ebf in ?? () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#31 0x00007fc4f090653f in ?? () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#32 0x00007fc4f08a9551 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#33 0x00007fc4f08b0930 in QApplication::notify(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#34 0x00007fc4f260f097 in KisApplication::notify (this=<optimized out>, receiver=0x55a18a3467a0, event=0x7fff184b82b0) at /home/boud/dev/krita/libs/ui/KisApplication.cpp:653
#35 0x00007fc4efee38e9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#36 0x00007fc4f02b9c6c in QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#37 0x00007fc4f02bb075 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#38 0x00007fc4f029505b in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#39 0x00007fc4e9c5467a in ?? () from /lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
#40 0x00007fc4ed3569ee in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#41 0x00007fc4ed356c88 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#42 0x00007fc4ed356d1c in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#43 0x00007fc4eff37047 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#44 0x00007fc4efee25bb in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#45 0x00007fc4f0a1d10d in QMenu::exec(QPoint const&, QAction*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#46 0x00007fc4d7835892 in LayerBox::slotContextMenuRequested (this=<optimized out>, pos=..., index=...) at /home/boud/dev/krita/plugins/dockers/layerdocker/LayerBox.cpp:699
#47 0x00007fc4d7835f3d in LayerBox::qt_static_metacall (_o=0x55a189e379f0, _c=<optimized out>, _id=<optimized out>, _a=<optimized out>) at /home/boud/dev/b-krita/plugins/dockers/layerdocker/kritalayerdocker_autogen/include/moc_LayerBox.cpp:233
#48 0x00007fc4eff0d426 in QMetaObject::activate(QObject*, int, int, void**) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#49 0x00007fc4d784cde7 in NodeView::contextMenuRequested (this=this@entry=0x55a189e825a0, _t1=..., _t2=...) at /home/boud/dev/b-krita/plugins/dockers/layerdocker/kritalayerdocker_autogen/EWIEGA46WW/moc_NodeView.cpp:224
#50 0x00007fc4d784ae1a in NodeView::showContextMenu (index=..., globalPos=..., this=<optimized out>) at /home/boud/dev/krita/plugins/dockers/layerdocker/NodeView.cpp:319
#51 NodeView::contextMenuEvent (this=0x55a189e825a0, e=0x7fff184b9180) at /home/boud/dev/krita/plugins/dockers/layerdocker/NodeView.cpp:314
#52 0x00007fc4f08e8b58 in QWidget::event(QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#53 0x00007fc4f098d6ce in QFrame::event(QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#54 0x00007fc4f0afee13 in QAbstractItemView::viewportEvent(QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#55 0x00007fc4f0b677bb in QTreeView::viewportEvent(QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#56 0x00007fc4d784a22b in NodeView::viewportEvent (this=0x55a189e825a0, e=0x7fff184b9180) at /home/boud/dev/krita/plugins/dockers/layerdocker/NodeView.cpp:305
#57 0x00007fc4efee35fb in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#58 0x00007fc4f08a9541 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#59 0x00007fc4f08b0dce in QApplication::notify(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#60 0x00007fc4f260f097 in KisApplication::notify (this=<optimized out>, receiver=0x55a189e82cb0, event=0x7fff184b9180) at /home/boud/dev/krita/libs/ui/KisApplication.cpp:653
#61 0x00007fc4efee38e9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#62 0x00007fc4f0903b68 in ?? () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#63 0x00007fc4f090653f in ?? () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#64 0x00007fc4f08a9551 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#65 0x00007fc4f08b0930 in QApplication::notify(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#66 0x00007fc4f260f097 in KisApplication::notify (this=<optimized out>, receiver=0x55a187e4d010, event=0x7fff184b96b0) at /home/boud/dev/krita/libs/ui/KisApplication.cpp:653
#67 0x00007fc4efee38e9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#68 0x00007fc4f02b9c6c in QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#69 0x00007fc4f02bb075 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#70 0x00007fc4f029505b in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#71 0x00007fc4e9c5467a in ?? () from /lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
#72 0x00007fc4ed3569ee in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#73 0x00007fc4ed356c88 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#74 0x00007fc4ed356d1c in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#75 0x00007fc4eff37047 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#76 0x00007fc4efee25bb in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#77 0x00007fc4efeea5e2 in QCoreApplication::exec() () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#78 0x000055a17f097212 in main (argc=<optimized out>, argv=0x7fff184b9d78) at /home/boud/dev/krita/krita/main.cc:535
[Inferior 1 (process 27362) detached]
Comment 2 Halla Rempt 2019-08-27 11:53:00 UTC
Updated backtrace:

Thread 1 (Thread 0x7f58cf6f0800 (LWP 5374)):
[KCrash Handler]
#6  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#7  0x00007f58d4a4c535 in __GI_abort () at abort.c:79
#8  0x00007f58d4e939a7 in QMessageLogger::fatal(char const*, ...) const () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#9  0x00007f58d4e92e29 in qt_assert(char const*, char const*, int) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#10 0x00007f58d64fc77a in QList<KisSharedPtr<KisNode> >::first (this=this@entry=0x7ffe133a6730) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:347
#11 0x00007f58d64f5c30 in KisLayerUtils::mergeMultipleLayersImpl (image=..., mergedNodes=..., putAfter=..., flattenSingleLayer=flattenSingleLayer@entry=true, actionName=..., cleanupNodes=cleanupNodes@entry=true, layerName=...) at /home/boud/dev/krita/libs/image/kis_layer_utils.cpp:1291
#12 0x00007f58d64f63ec in KisLayerUtils::flattenLayer (image=..., layer=...) at /home/boud/dev/krita/libs/image/kis_layer_utils.cpp:1464
#13 0x00007f58d64c5e20 in KisImage::flattenLayer (this=<optimized out>, layer=...) at /home/boud/dev/krita/libs/image/kis_image.cc:1287
#14 0x00007f58d74bb6f9 in tryFlattenGroupLayer (currentNode=..., image=...) at /home/boud/dev/krita/libs/ui/kis_layer_manager.cc:784
#15 0x00007f58d74bf379 in KisLayerManager::mergeLayer (this=0x564cb02f79d0) at /home/boud/dev/krita/libs/ui/kis_layer_manager.cc:808
#16 0x00007f58d78e2905 in KisLayerManager::qt_static_metacall (_o=<optimized out>, _c=<optimized out>, _id=<optimized out>, _a=0x7ffe133a69f0) at /home/boud/dev/b-krita/libs/ui/kritaui_autogen/EWIEGA46WW/moc_kis_layer_manager.cpp:173
#17 0x00007f58d50aa426 in QMetaObject::activate(QObject*, int, int, void**) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#18 0x00007f58d5a3ffe2 in QAction::triggered(bool) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#19 0x00007f58d5a425f0 in QAction::activate(QAction::ActionEvent) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#20 0x00007f58d5a42ea4 in QAction::event(QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#21 0x00007f58d5a46551 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#22 0x00007f58d5a4d930 in QApplication::notify(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Widgets.so.5
#23 0x00007f58d77c1bd7 in KisApplication::notify (this=<optimized out>, receiver=0x564cb031f050, event=0x7ffe133a6d70) at /home/boud/dev/krita/libs/ui/KisApplication.cpp:653
#24 0x00007f58d50808e9 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#25 0x00007f58d548122e in QShortcutMap::dispatchEvent(QKeyEvent*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#26 0x00007f58d548130b in QShortcutMap::tryShortcut(QKeyEvent*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#27 0x00007f58d5435ef6 in QWindowSystemInterface::handleShortcutEvent(QWindow*, unsigned long, int, QFlags<Qt::KeyboardModifier>, unsigned int, unsigned int, unsigned int, QString const&, bool, unsigned short) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#28 0x00007f58d5452efd in QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#29 0x00007f58d5458055 in QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#30 0x00007f58d543205b in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Gui.so.5
#31 0x00007f58ceff667a in ?? () from /lib/x86_64-linux-gnu/libQt5XcbQpa.so.5
#32 0x00007f58d26f89ee in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#33 0x00007f58d26f8c88 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#34 0x00007f58d26f8d1c in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#35 0x00007f58d50d4047 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#36 0x00007f58d507f5bb in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#37 0x00007f58d50875e2 in QCoreApplication::exec() () from /lib/x86_64-linux-gnu/libQt5Core.so.5
#38 0x0000564ca6960212 in main (argc=<optimized out>, argv=0x7ffe133a7508) at /home/boud/dev/krita/krita/main.cc:527
[Inferior 1 (process 5374) detached]
Comment 3 Halla Rempt 2019-08-27 11:58:31 UTC
Git commit 7ec84e5c194dedd77bd95a1943abff8500792de6 by Boudewijn Rempt.
Committed on 27/08/2019 at 11:56.
Pushed by rempt into branch 'master'.

Do not crash when trying to merge an invisible group

We should check whether a list contains any items before trying
to get the first item from the list.
BACKPORT:krita/4.2

M  +2    -2    libs/image/kis_layer_utils.cpp

https://invent.kde.org/kde/krita/commit/7ec84e5c194dedd77bd95a1943abff8500792de6
Comment 4 Halla Rempt 2019-08-30 13:22:27 UTC
*** Bug 410777 has been marked as a duplicate of this bug. ***
Comment 5 Halla Rempt 2019-09-10 08:27:56 UTC
Git commit e07edd17c7d4a69a7e6536707fe1bbabc9b7b8e8 by Boudewijn Rempt.
Committed on 10/09/2019 at 08:23.
Pushed by rempt into branch 'krita/4.2'.

Do not crash when trying to merge an invisible group

We should check whether a list contains any items before trying
to get the first item from the list.
BACKPORT:krita/4.2

M  +2    -2    libs/image/kis_layer_utils.cpp

https://invent.kde.org/kde/krita/commit/e07edd17c7d4a69a7e6536707fe1bbabc9b7b8e8