Bug 512243

Summary: Krita crashes when doing thin strokes with a smudge brush with certain configurations
Product: [Applications] krita Reporter: d.decent693
Component: Brush enginesAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: penguinflyer2222
Priority: NOR    
Version First Reported In: 5.2.13   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Crush log from the Krita's help menu.
A showcase for the crush
A bundle containing a brush which causes crashes

Description d.decent693 2025-11-17 15:36:38 UTC
Created attachment 186886 [details]
Crush log from the Krita's help menu.

SUMMARY


STEPS TO REPRODUCE
1. 
2. 
3. 

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma: 
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 d.decent693 2025-11-17 15:39:49 UTC
Created attachment 186887 [details]
A showcase for the crush
Comment 2 d.decent693 2025-11-17 15:50:09 UTC
Created attachment 186889 [details]
A bundle containing a brush which causes crashes
Comment 3 d.decent693 2025-11-17 15:56:42 UTC
Oh, sorry I accidentally pressed enter and didn't finish the report :/

I attached the text file with the information from the report bug Krita's menu. I also added a little showcase of the bug and a bundle containing the brush. If you need additional info please let me know.

Steps to reproduce:

As said above I attached the bundle with the brush which causes it.

So crushes happen when I make thin strokes with a smudge brush, which has certain configuration. I tried to narrow down the specific options, and it seems that when a size of the brush is 160 px, it has rotation with the drawing angle sensor, has linear tilt elevation with the x axis on the end raised to 5%, and some brush tips (not all), it crushes.

I tried to reinstall Krita, but it didn't help, I also updated the driver of my XP Pen tablet and restart the computer, but didn't help too.

Some basic info:

Krita

 Version: 5.2.13 (git 6d3651a)
 Installation type: installer / portable package
 Hidpi: true

Qt

  Version (compiled): 5.15.7
  Version (loaded): 5.15.7

OS Information

  Build ABI: x86_64-little_endian-llp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: winnt
  Kernel Version: 10.0.26100
  Pretty Productname: Windows 10 Version 2009
  Product Type: windows
  Product Version: 10
Comment 4 Freya Lupen 2025-11-20 21:48:18 UTC
Confirmed with the attached brush. The issue only happens with Smearing mode, even though the mode is set under Smudge Length, which isn't enabled. (Checking the mode when it's disabled seems like a bug too?)

The short version is it's a decimal rounding issue that can happen under some circumstances.
The long technical explanation:

We assert here:
> ASSERT (krita): "selBounds.contains(selRect)" in file /krita/libs/image/kis_painter.cc, line 1057
The values are:
> selBounds QRect(0,0 8x8) selRect QRect(0,0 9x9)

These values can be seen in a commented-out warning in KisQImagePyramid::calculateParams() as well:
> krita.general: WARNING: expected and real dab rects do not coincide!
> krita.general:          expected rect: QRect(0,0 9x9)
> krita.general:          real rect:     QRect(0,0 8x8)

The "expected" rect is based on transforming the original brushtip size (256x256).
The "real" rect is based on the transforming the scaled brushtip size's closest size in the pyramid of power-of-2 levels (8x8).

The brush has a size curve where 100% tilt elevation is .05 size.
But, somehow in KisDynamicSensor::parameter(), the size scale value ends up as 0.05000000000000004.

When multiplying that size scale by the scale of the brush preset size to the brushtip size (160/256 = .625), we then end up with a dab scale of 0.03125000000000003 instead of just 0.03125 (8/256).

Then the "expected" dab size (dab scale * brushtip size) ends up as 8.000000000000007 instead of 8. That dab size is passed to the roundRect() function, which uses QRectF.toAlignedRect() to round up non-integer rectangles.
Since there's that tiny fraction, we end up with an "expected" dab size of 9x9.

The "real" dab size is calculated by dividing the "expected" dab scale  of 0.03125000000000003 by the scale of the scaled dab to the original brushtip (8/256, .03125). We end of with a "real" dab scale of 1.000000000000001, multipled by the scaled dab size 8 to get a "real" dab size of 8.000000000000000 (or 8.00000000000000008; two more decimals).
It's apparently too small for toAlignedRect() to round up, and we get a "real" dab size of 8x8.

However, the above dab sizes are all with no transformation applied.
If there's subpixel translation, the rects will be rounded up to contain the fractional positions. If the dab is rotated, the transformed dab's size will likely be a large enough fraction to round up with toAlignedRect regardless of whether it's the original or scaled dab.

Thus the crash (assert) only happens in Smearing mode, where subpixel precision is disabled, and when the rotation angle happens to be 0.
Comment 5 Dmitry Kazakov 2025-12-09 09:15:23 UTC
Git commit 4323f26c2856a5353d631e77ff6ffcf380361544 by Dmitry Kazakov, on behalf of Luna Lovecraft.
Committed on 09/12/2025 at 09:15.
Pushed by dkazakov into branch 'master'.

Fix crash when using a smudge brush

Test Plan
---------

1. Open document
2. Select the brush in [this bundle](https://bugs.kde.org/attachment.cgi?id=186889)
3. Do a bunch of strokes
4. No crash

M  +13   -0    libs/brush/kis_qimage_pyramid.cpp

https://invent.kde.org/graphics/krita/-/commit/4323f26c2856a5353d631e77ff6ffcf380361544
Comment 6 Dmitry Kazakov 2025-12-09 09:15:50 UTC
Git commit 825fadde58fab173e7e38f283578a31ea34ba04e by Dmitry Kazakov.
Committed on 09/12/2025 at 09:15.
Pushed by dkazakov into branch 'krita/5.2'.

Fix crash when using a smudge brush

Test Plan
---------

1. Open document
2. Select the brush in [this bundle](https://bugs.kde.org/attachment.cgi?id=186889)
3. Do a bunch of strokes
4. No crash


(cherry picked from commit 4323f26c2856a5353d631e77ff6ffcf380361544)

ffccd67c Fix crash when using a smudge brush

Co-authored-by: Luna Lovecraft <ciubix8514@gmail.com>

M  +13   -0    libs/brush/kis_qimage_pyramid.cpp

https://invent.kde.org/graphics/krita/-/commit/825fadde58fab173e7e38f283578a31ea34ba04e
Comment 7 Dmitry Kazakov 2025-12-09 09:16:13 UTC
Git commit 288f975b6dd188f448ff19e106a2c9033d054085 by Dmitry Kazakov.
Committed on 09/12/2025 at 09:16.
Pushed by dkazakov into branch 'release/5.2.14'.

Fix crash when using a smudge brush

Test Plan
---------

1. Open document
2. Select the brush in [this bundle](https://bugs.kde.org/attachment.cgi?id=186889)
3. Do a bunch of strokes
4. No crash


(cherry picked from commit 4323f26c2856a5353d631e77ff6ffcf380361544)

ffccd67c Fix crash when using a smudge brush

Co-authored-by: Luna Lovecraft <ciubix8514@gmail.com>

M  +13   -0    libs/brush/kis_qimage_pyramid.cpp

https://invent.kde.org/graphics/krita/-/commit/288f975b6dd188f448ff19e106a2c9033d054085