Bug 408887

Summary: Crash when using shrink option on the deform brush engine
Product: [Applications] krita Reporter: daefunct
Component: Brush enginesAssignee: Halla Rempt <halla>
Status: RESOLVED FIXED    
Severity: crash CC: ahab.greybeard, halla
Priority: NOR Keywords: regression
Version: 4.2.1   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Attachments: Old deevad deform preset that causes crash
Brush causing problems

Description daefunct 2019-06-18 21:23:31 UTC
SUMMARY
Shrinking with the deform brush engine crashes Krita

STEPS TO REPRODUCE
1. select a deform engine brush
2. set the mode to shrink
3. shrink something down to a small point

OBSERVED RESULT
crash

EXPECTED RESULT
:)

SOFTWARE/OS VERSIONS
Windows: 10
Comment 1 Ahab Greybeard 2019-06-19 13:27:09 UTC
I can confirm this for krita 4.2.1 on Windows 10.

Using the Deevead 2a Deform brush, set to Shrink mode, a crash happens soon after operations on a layer.
If you use it in its normal (move) mode or grow mode for a while, then change it to shrink mode, it doesn't crash for a while if at all.
Selecting/deselecting various options in the brush doesn't seem to have much influence on this as far as I can tell.
Comment 2 Halla Rempt 2019-06-20 13:08:44 UTC
I cannot reproduce this on Linux. Would it be possible to get a crash log? See https://docs.krita.org/en/reference_manual/dr_minw_debugger.html#dr-minw -- preferably made with the latest nightly build (https://binary-factory.kde.org/job/Krita_Nightly_Windows_Build/)
Comment 3 Ahab Greybeard 2019-06-20 16:17:31 UTC
Created attachment 121036 [details]
Old deevad deform preset that causes crash

This has become more complicated:

I attach the old Deevad_2a_deform brush preset which will cause a crash in a 4.2.0 and later appimages when set to shrink.

When I got the freeze and Windows system reporting of krita not responding, I'd randomly choosen and used the Deevad 2a Deform brush preset, manually changing it to the shrink option. This brush preset is no longer provided in the standard bundles and was from an old bundle that I have.

Using this preset in the 4.2.1 and later Linux appimages, after setting it to shrink, causes a crash in a very short time.
The 4.1.7 appimage does not crash.

Before any further investigation:
Can the report author provide information about which brush preset was being used? If the author had created their own brush preset, can they attach it to a comment?

I tried creating a new/fresh brush preset that used the Deform engine, set to shrink, and I could not get that to crash under a variety of situations. I tried editing existing standard deform presets to shrink and could not get a crash. It only happens with the old Deevad_2a_deform preset set to shrink.

Additional note: The Deeved_2a_deform preset performs well as a shrinking brush (when it doesn't crash krita) compared to other shrinking deform presets that behave differently on a boundary with a transparent area and do in fact cause a painted area to grow. I've been unable to recreate the characteristics of the Deevad preset using the brush editor on other deform brushes in the 4.2.1 and later versions.
Comment 4 daefunct 2019-06-21 18:54:51 UTC
Created attachment 121064 [details]
Brush causing problems
Comment 5 daefunct 2019-06-21 18:56:17 UTC
I'm not seeing a recent log in kritacrash.log
I think I'm also using an old move brush. I'll attach it. Making a new brush doesn't give me any problems at all.
Comment 6 Ahab Greybeard 2019-06-21 19:23:04 UTC
Yes, that old move brush gives me a crash when edited to Shrink. I'm sure the problem will be solved eventually.

Note: For attachments of anything except image files, text files and zip files, it seems that downloading is inconvenient so I'll try to remember to zip up any future .kpp etc files.
Comment 7 Halla Rempt 2019-06-24 07:30:33 UTC
Backtrace: 

ASSERT (krita): "row < 0x7FFF && col < 0x7FFF" in file /home/boud/dev/krita/libs/image/tiles3/kis_tile_hash_table2.h, line 133

Thread 44 "Thread (pooled)" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fff967fc700 (LWP 20738)]
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff295e801 in __GI_abort () at abort.c:79
#2  0x00007ffff3333f2b in QMessageLogger::fatal(char const*, ...) const ()
   from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#3  0x00007ffff4c8e91e in kis_assert_common (
    assertion=assertion@entry=0x7ffff577fee2 "row < 0x7FFF && col < 0x7FFF", 
    file=file@entry=0x7ffff577fda0 "/home/boud/dev/krita/libs/image/tiles3/kis_tile_hash_table2.h", 
    line=line@entry=133, throwException=throwException@entry=false, isIgnorable=isIgnorable@entry=false)
    at /home/boud/dev/krita/libs/global/kis_assert.cpp:90
#4  0x00007ffff4c8ea3a in kis_assert_recoverable (
    assertion=assertion@entry=0x7ffff577fee2 "row < 0x7FFF && col < 0x7FFF", 
    file=file@entry=0x7ffff577fda0 "/home/boud/dev/krita/libs/image/tiles3/kis_tile_hash_table2.h", 
    line=line@entry=133) at /home/boud/dev/krita/libs/global/kis_assert.cpp:103
#5  0x00007ffff53ab4d8 in KisTileHashTableTraits2<KisTile>::calculateHash (this=0x555561e1a320, row=-56169, 
    col=94168) at /home/boud/dev/krita/libs/image/tiles3/kis_tile_hash_table2.h:133
#6  KisTileHashTableTraits2<KisTile>::getReadOnlyTileLazy (this=0x555561e1a320, col=94168, row=-56169, 
    existingTile=@0x7fff967fac40: false) at /home/boud/dev/krita/libs/image/tiles3/kis_tile_hash_table2.h:375
#7  0x00007ffff53c1735 in KisTiledDataManager::getTile (writable=<optimized out>, row=-56169, col=94168, 
    this=0x555561d2eee0) at /home/boud/dev/krita/libs/image/tiles3/kis_tiled_data_manager.h:128
#8  KisTiledDataManager::getTilesPair (oldTile=0x7fff8800ebf8, tile=0x7fff8800ebf0, writable=<optimized out>, 
    row=-56169, col=94168, this=0x555561d2eee0)
    at /home/boud/dev/krita/libs/image/tiles3/kis_tiled_data_manager.h:107
#9  KisRandomAccessor2::fetchTileData (this=this@entry=0x7fff8800ce50, col=94168, row=-56169)
    at /home/boud/dev/krita/libs/image/tiles3/kis_random_accessor.cc:122
#10 0x00007ffff53c2002 in KisRandomAccessor2::moveTo (this=0x7fff8800ce50, x=6026780, y=-3594768)
    at /home/boud/dev/krita/libs/image/tiles3/kis_random_accessor.cc:89
#11 0x00007ffff566cb08 in KisRandomSubAccessor::sampledRawData (this=this@entry=0x7fff8800e1d0, 
    dst=dst@entry=0x7fff88003a90 "") at /home/boud/dev/krita/libs/image/kis_random_sub_accessor.cpp:80
#12 0x00007fffb80a9bb2 in PickerTraitReal::sampleData<false> (data=0x7fff88003a90 "", accessor=...)
    at /home/boud/dev/krita/libs/image/kis_cross_device_color_picker.h:38
#13 KisCrossDeviceColorPickerImpl<PickerTraitReal>::pickColorImpl<false> (dst=0x7fff8801eef0 "", 
    y=<optimized out>, x=<optimized out>, this=<synthetic pointer>)
    at /home/boud/dev/krita/libs/image/kis_cross_device_color_picker.h:121
#14 KisCrossDeviceColorPickerImpl<PickerTraitReal>::pickColor (dst=0x7fff8801eef0 "", y=<optimized out>, 
    x=<optimized out>, this=<synthetic pointer>)
    at /home/boud/dev/krita/libs/image/kis_cross_device_color_picker.h:96
#15 DeformBrush::paintMask (this=this@entry=0x7fff7c00a2a0, dab=..., layer=..., scale=scale@entry=1, 
    rotation=rotation@entry=0, pos=..., subPixelX=subPixelX@entry=0.2228398328768435, 
    subPixelY=subPixelY@entry=0.34434506453101221, dabX=dabX@entry=504, dabY=dabY@entry=297)
    at /home/boud/dev/krita/plugins/paintops/deform/deform_brush.cpp:250
#16 0x00007fffb80ae4b6 in KisDeformPaintOp::paintAt (this=0x7fff7c00a270, info=...)
    at /home/boud/dev/krita/plugins/paintops/deform/kis_deform_paintop.cpp:134
#17 0x00007ffff53fc241 in KisPaintInformation::paintAt<KisPaintOp> (distanceInfo=0x5555621a4020, op=..., 
    this=0x7fff967fb710) at /home/boud/dev/krita/libs/image/brushengine/kis_paint_information.h:117
#18 KisPaintOpUtils::paintLine<KisPaintOp> (op=..., pi1=..., pi2=..., 
    currentDistance=currentDistance@entry=0x5555621a4020, fanCornersEnabled=false, fanCornersStep=1)
    at /home/boud/dev/krita/libs/image/brushengine/kis_paintop_utils.h:96
#19 0x00007ffff53fbafd in KisPaintOp::paintLine (currentDistance=0x5555621a4020, pi2=..., pi1=..., 
    this=0x7fff7c00a270) at /home/boud/dev/krita/libs/image/brushengine/kis_paintop.cc:156
#20 paintBezierCurve (paintOp=0x7fff7c00a270, pi1=..., control1=..., control2=..., pi2=..., 
    currentDistance=0x5555621a4020) at /home/boud/dev/krita/libs/image/brushengine/kis_paintop.cc:125
#21 0x00007ffff53fbc82 in KisPaintOp::paintBezierCurve (this=<optimized out>, pi1=..., control1=..., 
    control2=..., pi2=..., currentDistance=<optimized out>)
    at /home/boud/dev/krita/libs/image/brushengine/kis_paintop.cc:148
#22 0x00007ffff6ae9a27 in KisMaskedFreehandStrokePainter::<lambda(KisFreehandStrokeInfo*)>::operator() (
    data=<optimized out>, data=<optimized out>, __closure=<synthetic pointer>)
---Type <return> to continue, or q <return> to quit---
    at /home/boud/dev/krita/libs/ui/tool/strokes/KisMaskedFreehandStrokePainter.cpp:67
#23 KisMaskedFreehandStrokePainter::applyToAllPainters<KisMaskedFreehandStrokePainter::paintBezierCurve(const KisPaintInformation&, const QPointF&, const QPointF&, const KisPaintInformation&)::<lambda(KisFreehandStrokeInfo*)> >
    (func=..., this=0x7fff7c009580, this@entry=0x555561c70498)
    at /home/boud/dev/krita/libs/ui/tool/strokes/KisMaskedFreehandStrokePainter.cpp:43
#24 KisMaskedFreehandStrokePainter::paintBezierCurve (this=this@entry=0x7fff7c009580, pi1=..., control1=..., 
    control2=..., pi2=...) at /home/boud/dev/krita/libs/ui/tool/strokes/KisMaskedFreehandStrokePainter.cpp:66
#25 0x00007ffff6ad9cd8 in FreehandStrokeStrategy::doStrokeCallback (this=0x555560d27c00, data=<optimized out>)
    at /home/boud/dev/krita/libs/ui/tool/strokes/freehand_stroke.cpp:179
#26 0x00007ffff577d340 in non-virtual thunk to KisUpdateJobItem::run() ()
   from /home/boud/dev/i-krita/lib/x86_64-linux-gnu/libkritaimage.so.19
#27 0x00007ffff335c3e2 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#28 0x00007ffff3357c72 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#29 0x00007fffec4f36db in start_thread (arg=0x7fff967fc700) at pthread_create.c:463
#30 0x00007ffff2a3f88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
Comment 8 Halla Rempt 2019-06-24 07:38:50 UTC
Git commit 103d4b79dac9e4fb38ed4e9acb0c66b4343ed00d by Boudewijn Rempt.
Committed on 24/06/2019 at 07:38.
Pushed by rempt into branch 'master'.

Use a safe assert here

M  +1    -1    libs/image/tiles3/kis_tile_hash_table2.h

https://invent.kde.org/kde/krita/commit/103d4b79dac9e4fb38ed4e9acb0c66b4343ed00d
Comment 9 Halla Rempt 2019-06-24 08:21:45 UTC
Git commit 9be2cc9263e8d9d365ef5d8884aec93521736244 by Boudewijn Rempt.
Committed on 24/06/2019 at 08:21.
Pushed by rempt into branch 'krita/4.2'.

Use a safe assert here

M  +1    -1    libs/image/tiles3/kis_tile_hash_table2.h

https://invent.kde.org/kde/krita/commit/9be2cc9263e8d9d365ef5d8884aec93521736244
Comment 10 Halla Rempt 2019-06-24 10:45:26 UTC
Before the transform call:

maskX: -27.2759 
maskY: -31.4891 
distance: 0.173553

After:

maskX: 6.5584e+07 
maskY: 7.57144e+07
Comment 11 Dmitry Kazakov 2019-06-24 12:31:17 UTC
Git commit 7b0d5683c6cad0ff294848d579bd98761071f385 by Dmitry Kazakov.
Committed on 24/06/2019 at 12:29.
Pushed by dkazakov into branch 'master'.

Fix a crash when using "shrink" deform brush

M  +2    -1    plugins/paintops/deform/deform_brush.h

https://invent.kde.org/kde/krita/commit/7b0d5683c6cad0ff294848d579bd98761071f385
Comment 12 Halla Rempt 2019-07-08 14:59:27 UTC
Git commit 7319fd1b2bbe74b8ef22cc198143ebb4e859eb6f by Boudewijn Rempt, on behalf of Dmitry Kazakov.
Committed on 08/07/2019 at 14:59.
Pushed by rempt into branch 'krita/4.2'.

Fix a crash when using "shrink" deform brush

M  +2    -1    plugins/paintops/deform/deform_brush.h

https://invent.kde.org/kde/krita/commit/7319fd1b2bbe74b8ef22cc198143ebb4e859eb6f