Bug 466963

Summary: Filter Mask window crashes when choosing Map > Palettize
Product: [Applications] krita Reporter: jm.info.only
Component: Filter LayersAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: penguinflyer2222
Priority: NOR    
Version First Reported In: 5.1.5   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Brief moment app hangs and is about to crash.

Description jm.info.only 2023-03-06 19:08:03 UTC
Created attachment 157060 [details]
Brief moment app hangs and is about to crash.

SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***


STEPS TO REPRODUCE
1.  Click Add on the layers dock.
2.  Choose a new Filter Mask.
3.  Navigate to Map > Palettize.

OBSERVED RESULT
Krita stalls then crashes.

EXPECTED RESULT
No crashing.

SOFTWARE/OS VERSIONS
Windows:  10

ADDITIONAL INFORMATION
Screenshot attached.  Happening in latest version.
Comment 1 Freya Lupen 2023-03-30 04:40:47 UTC
Confirming that the Palettize filter dialog has a tendency to stop responding or crash, whether viewed through the Filters menu or the Filter Mask dialog, on 5.1.5 and 5.2.x. (Mostly tested on 5.2.x.)
On Windows it usually stops responding. Turning off HiDPI support seems to let the Filter dialog work, but the Filter Mask dialog still crashes. On Linux it sometimes works and sometimes crashes.

I tried turning HiDPI off because the backtrace while the Filter dialog hangs shows KisIconWidget::paintEvent() calling for DPI metrics.
>     frame #5: 0x00007fff28362bfc Qt5Gui.dll`QWindow::devicePixelRatio() const at qwindow.cpp:1322:52
>     frame #6: 0x00007fff5b1caf25 Qt5Widgets.dll`QWidget::metric(QPaintDevice::PaintDeviceMetric) const at qwidget.cpp:12598:51
>     frame #7: 0x00007fff14d11a0f libkritaui.dll`std::__1::__function::__func<KisIconWidget::paintEvent(QPaintEvent*)::$_2, std::__1::allocator<KisIconWidget::paintEvent(QPaintEvent*)::$_2>, void (QPainter&)>::operator()(QPainter&) [inlined] QPaintDevice::devicePixelRatioF(this=0x000001718d952100) const at qpaintdevice.h:87:47

The Filter Mask dialog seems to crash in QMapData of KisSwatch, from KisFilterPalettize::processImpl().
> * thread #122, stop reason = Exception 0xc0000005 encountered at address 0x7fff09194d86: Access violation reading location 0xffffffffffffffff
>   * frame #0: 0x00007fff09194d86 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(int const&, KisSwatch const&, QMapNode<int, KisSwatch>*, bool) [inlined] int std::__1::__cxx_atomic_load[abi:v15000]<int>(__a=0xfeeefeeefeeefeee, __order=memory_order_relaxed) at atomic:958:12
>     frame #1: 0x00007fff09194d86 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(int const&, KisSwatch const&, QMapNode<int, KisSwatch>*, bool) [inlined] std::__1::__atomic_base<int, false>::load[abi:v15000](this=0xfeeefeeefeeefeee, __m=memory_order_relaxed) const at atomic:1588:17
>     frame #2: 0x00007fff09194d86 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(int const&, KisSwatch const&, QMapNode<int, KisSwatch>*, bool) [inlined] int QAtomicOps<int>::loadRelaxed<int>(_q_value=0xfeeefeeefeeefeee) at qatomic_cxx11.h:239:25
>     frame #3: 0x00007fff09194d86 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(int const&, KisSwatch const&, QMapNode<int, KisSwatch>*, bool) [inlined] QBasicAtomicInteger<int>::loadRelaxed(this=0xfeeefeeefeeefeee) const at qbasicatomic.h:107:45
>     frame #4: 0x00007fff09194d86 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(int const&, KisSwatch const&, QMapNode<int, KisSwatch>*, bool) [inlined] QtPrivate::RefCount::ref(this=0xfeeefeeefeeefeee) at qrefcount.h:55:28
>     frame #5: 0x00007fff09194d86 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(int const&, KisSwatch const&, QMapNode<int, KisSwatch>*, bool) [inlined] QMap<QString, QVariant>::QMap(this=0x000001c2c40d9298, other=0x000001c2f629d3f8) at qmap.h:631:22
>     frame #6: 0x00007fff09194d82 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(int const&, KisSwatch const&, QMapNode<int, KisSwatch>*, bool) [inlined] KoColor::KoColor(this=0x000001c2c40d9260, rhs=0x000001c2f629d3c0) at KoColor.h:54:11
>     frame #7: 0x00007fff09194d74 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(int const&, KisSwatch const&, QMapNode<int, KisSwatch>*, bool) [inlined] KisSwatch::KisSwatch(this=0x000001c2c40d9260, (null)=0x000001c2f629d3c0) at KisSwatch.h:17:27
>     frame #8: 0x00007fff09194d74 libkritapigment.dll`QMapData<int, KisSwatch>::createNode(this=0x000001c2c7f22ea0, k=0x000001c2f629d3b8, v=0x000001c2f629d3c0, parent=<unavailable>, left=<unavailable>) at qmap.h:231:33
>     frame #9: 0x00007fff09194cc9 libkritapigment.dll`QMapNode<int, KisSwatch>::copy(this=0x000001c2f629d3a0, d=0x000001c2c7f22ea0) const at qmap.h:259:30
>     frame #10: 0x00007fff09194cf0 libkritapigment.dll`QMapNode<int, KisSwatch>::copy(this=0x000001c2c3dc3e70, d=0x000001c2c7f22ea0) const at qmap.h:262:31
>     frame #11: 0x00007fff09194cf0 libkritapigment.dll`QMapNode<int, KisSwatch>::copy(this=0x000001c2fad216e0, d=0x000001c2c7f22ea0) const at qmap.h:262:31
>     frame #12: 0x00007fff09195317 libkritapigment.dll`QMap<int, KisSwatch>::detach_helper(this=0x000001c2fab47db8) at qmap.h:976:63
>     frame #13: 0x00007fff091939ff libkritapigment.dll`KisSwatchGroup::getSwatch(int, int) const [inlined] QMap<int, KisSwatch>::detach(this=0x000001c2fab47db8) at qmap.h:361:51
>     frame #14: 0x00007fff091939ec libkritapigment.dll`KisSwatchGroup::getSwatch(int, int) const [inlined] QMap<int, KisSwatch>::operator[](this=0x000001c2fab47db8, akey=0x00000082c47fe91c) at qmap.h:680:5
>     frame #15: 0x00007fff091939ec libkritapigment.dll`KisSwatchGroup::getSwatch(this=<unavailable>, column=2, row=0) const at KisSwatchGroup.cpp:153:12
>     frame #16: 0x00007fff0917b5a9 libkritapigment.dll`KoColorSet::getColorGlobal(this=<unavailable>, column=2, row=0) const at KoColorSet.cpp:654:19
>     frame #17: 0x00007ffef0ef4a13 kritapalettize.dll`KisFilterPalettize::processImpl(this=<unavailable>, device=KisPaintDeviceSP @ 0x00000082c47ff398, applyRect=0x00000082c47ff7f0, _config=KisFilterConfigurationSP @ 0x00000082c47ff390, progressUpdater=0x000001c2ea86ccd0) const at palettize.cpp:276:45
Comment 2 Bug Janitor Service 2023-04-17 16:15:06 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1786
Comment 3 Dmitry Kazakov 2023-06-19 11:12:21 UTC
Git commit 62f0e49a770557c8ccf52027605eb617dcd7758d by Dmitry Kazakov.
Committed on 19/06/2023 at 10:52.
Pushed by dkazakov into branch 'master'.

Fix crash in Palettize filter

The patch just wraps the d-poitner structure into
std::experimental::propagate_const, which disables detaching
of the QMap on every color-swatch access.

This propagate_const is still in 'experimental' land, the patch
also includes a fallback inmplementation from Jonathan B. Coe,
from GitHub: https://github.com/jbcoe/propagate_const

A  +427  -0    libs/global/3rdparty/propagate_const.h  *
A  +15   -0    libs/global/KisPropagateConstWrapper.h     [License: GPL(v2.0+)]
M  +1    -1    libs/pigment/resources/KisSwatchGroup.cpp
M  +7    -2    libs/pigment/resources/KisSwatchGroup.h

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/graphics/krita/-/commit/62f0e49a770557c8ccf52027605eb617dcd7758d