Bug 432329

Summary: Painting on filter masks created from vector selections generally produces crashes or artifacts
Product: [Applications] krita Reporter: tomtomtomreportingin
Component: Tools/FreehandAssignee: Dmitry Kazakov <dimula73>
Status: RESOLVED FIXED    
Severity: crash CC: dimula73
Priority: NOR Keywords: regression
Version: 4.4.2   
Target Milestone: ---   
Platform: Appimage   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Filter mask artifact

Description tomtomtomreportingin 2021-01-31 03:07:12 UTC
SUMMARY
Starting with Krita 4.4.0, I can observe crashes when painting on filter masks that have been created from vector selections. I can observe artifacts before this version in 4.3.0, but not the crashes, although the behavior somewhat randomly reproduces in general.

STEPS TO REPRODUCE
1. Select a selection tool, enable Vector selection, create a selection.
2. Add a filter mask, for example with Random Noise.
3. Paint on it with the Freehand Brush tool.

OBSERVED RESULT
You will likely encounter either artifacts or a segmentation fault. If neither happens with the first stroke, you can undo the stroke and try again. If it still doesn't happen, undo all the steps and try again.

EXPECTED RESULT
No crash or artifacts.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Debian sid
(available in About System)
KDE Plasma Version: 5.20.5
KDE Frameworks Version: 5.78.0
Qt Version: 5.12.9 (Appimage)

ADDITIONAL INFORMATION
I have not checked betas. I have not observed this happening with pixel selections. This happens regardless if you add a filter mask from the Layers Docker or if you add a filter mask from the Menu bar -> Filters -> [Filter] -> Create Filter Mask. (Somewhat unrelated note, I noticed that the former action removes the selection mask while the latter action keeps the selection mask. Is this intentional, and if so, should I file it as a separate report?)
Comment 1 Dmitry Kazakov 2021-02-03 11:46:03 UTC
Git commit 6fc84c8bff6821d9866a7d7da871e10294536c8a by Dmitry Kazakov.
Committed on 03/02/2021 at 11:45.
Pushed by dkazakov into branch 'master'.

Workaround recursive calls in UndoStack

In some cases, when the user clicks in the history docker too
quickly, the undo requests may arrive recursively. Because there
are a few commands that demand processEvent() calls after their
execution. This patch workarounds the recursive issue using the
ticket-like system for the requests and ensuring that all of them
are executed at the topmost level of recursion.

M  +72   -12   libs/ui/KisDocument.cpp

https://invent.kde.org/graphics/krita/commit/6fc84c8bff6821d9866a7d7da871e10294536c8a
Comment 2 Dmitry Kazakov 2021-02-04 13:01:45 UTC
Git commit 9321eb2b22f0a330ba5d63bb7bb03a779de8fe28 by Dmitry Kazakov.
Committed on 04/02/2021 at 12:55.
Pushed by dkazakov into branch 'master'.

Crash when undoing reincarnation of a shape selection too quickly

It may happen that the update jobs are still accessing the shape
selection pointer via KisSelection::updateProjection(), while
undo command is busy reincarnating the shape selection into a
raster one.

We should guard the shape selection pointer from such concurrent
access.

M  +50   -4    libs/image/kis_selection.cc

https://invent.kde.org/graphics/krita/commit/9321eb2b22f0a330ba5d63bb7bb03a779de8fe28
Comment 3 Dmitry Kazakov 2021-02-17 06:04:18 UTC
Git commit d97692a969b2bd2ca553eb004f5eba71ea33e452 by Dmitry Kazakov.
Committed on 17/02/2021 at 05:38.
Pushed by dkazakov into branch 'krita/4.3'.

Workaround recursive calls in UndoStack

In some cases, when the user clicks in the history docker too
quickly, the undo requests may arrive recursively. Because there
are a few commands that demand processEvent() calls after their
execution. This patch workarounds the recursive issue using the
ticket-like system for the requests and ensuring that all of them
are executed at the topmost level of recursion.

M  +72   -12   libs/ui/KisDocument.cpp

https://invent.kde.org/graphics/krita/commit/d97692a969b2bd2ca553eb004f5eba71ea33e452
Comment 4 Dmitry Kazakov 2021-02-17 06:04:34 UTC
Git commit 9887c3717152f6dbbd127ed69dcba2d4011d9472 by Dmitry Kazakov.
Committed on 17/02/2021 at 05:38.
Pushed by dkazakov into branch 'krita/4.3'.

Crash when undoing reincarnation of a shape selection too quickly

It may happen that the update jobs are still accessing the shape
selection pointer via KisSelection::updateProjection(), while
undo command is busy reincarnating the shape selection into a
raster one.

We should guard the shape selection pointer from such concurrent
access.

M  +50   -4    libs/image/kis_selection.cc

https://invent.kde.org/graphics/krita/commit/9887c3717152f6dbbd127ed69dcba2d4011d9472
Comment 5 tomtomtomreportingin 2021-02-26 03:08:06 UTC
Hi Dmitry, while the crash does seem to be fixed now in 4.4.3 beta-1, the rectangular artifacts described in the report still seem to exist. Also, it seems that these artifacts are more than visual, as they seem to genuinely affect the painting area, so they cannot be wiped away by hiding and unhiding the layer. I'll attach an image showing this artifact and how it affects the canvas.
Comment 6 tomtomtomreportingin 2021-02-26 03:08:56 UTC
Created attachment 136177 [details]
Filter mask artifact