Bug 407659 - [brush presets] Random switch of brush preset while painting
Summary: [brush presets] Random switch of brush preset while painting
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Usability (show other bugs)
Version: 4.2.0-alpha
Platform: Appimage Linux
: NOR normal
Target Milestone: ---
Assignee: Halla Rempt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-17 19:36 UTC by David REVOY
Modified: 2019-05-27 10:07 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
^ My kritarc file; captured right after the bug#2 video (without closing krita) (96.55 KB, text/plain)
2019-05-18 13:10 UTC, David REVOY
Details
^ screenshot of the log, with ID switching marked (*403 VS *755), for archives (763.26 KB, image/jpeg)
2019-05-27 10:07 UTC, David REVOY
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David REVOY 2019-05-17 19:36:32 UTC
Hi,
This is a bug happening to me every hours while painting in Krita since a long time. I consider this bug as my 1st annoyance when painting/drawing with Krita. I remember talking about since last Sprint in may 2017. It might have born when Krita became 4.x. Unfortunately I never found a way to reproduce with steps this bug and I never reported exept on IRC, sprint meetings, etc...

But as the bug happens often, Scott gave me the idea (thanks!) this week to video capture it. So, I caught one :-) Here under is a first video capture without audio but captions, followed by a breakdown of the video frame by frame describing all I can see happening during this switch. It was interesting to see this happening not in the middle of nowhere, but still unreproducable... I'm opening this bug report because maybe it will give a hint about what's happening on your trained eyes:

Video:
======
https://www.peppercarrot.com/extras/videos/2019-05-17_random-preset-switch-bug_investigation-A.mp4 (1min30 - MP4)

Note: captured on krita-4.2.0-alpha-ca5aeb7-x86_64.appimage (a nightly from 2 days ago.) but all 4.x I tested have that.
Comment 1 Halla Rempt 2019-05-17 19:46:51 UTC
* does it always seem to switch between the same two presets in one session?
* that saving progress bar was around for an awfully long time, wasn't it?
* I guess you're sure that there isn't anything in your setup that sends a / now and then?
Comment 2 Scott Petrovic 2019-05-17 19:53:39 UTC
That is quite odd. I wonder if there is any code that saves the last used preset to the KRA file?

One thought is that the saving is somehow getting the current preset brush in an incorrect state. Then when painting again the engine tries to grab a preset and it is grabbing the wrong one.
Comment 3 David REVOY 2019-05-17 19:56:06 UTC
> does it always seem to switch between the same two presets in one session?

The target preset (the one happening by accident) is −I think− the last one I had when I closed previous Krita. (and so, the first one I had when I opened the new Krita).

> that saving progress bar was around for an awfully long time, wasn't it?

Yes, all my save does that. [Saving Document:...0%] written during long time, and then disapearing, no progress bar, no incremental percent written.

> I guess you're sure that there isn't anything in your setup that sends a / now and then?
:-) I double checked; no. It doesn't switch the preset I used before the one I have so it isn't a / action. It is like if Krita load a new fictive device (like flipping the stylus to eraser... or the mouse). In all case it happens when the stylus is not touching the canvas. It never happened while I was painting, but between strokes.
Comment 4 Halla Rempt 2019-05-17 20:52:20 UTC
Afair, the last used preset is saved in the kritarc, not the kra file.
Comment 5 David REVOY 2019-05-18 13:10:48 UTC
Created attachment 120165 [details]
^ My kritarc file; captured right after the bug#2 video (without closing krita)

Hi!

I found a second case today while sketching. This time the random switch happened differently; after flipping back the stylus from eraser. As usual when the bug happens, I stop recording and crop only the end part to see how it happens. The short video #2 with caption is here:

https://www.peppercarrot.com/extras/videos/2019-05-17_random-preset-switch-bug_investigation-B.mp4

Note: Krita switches to the same preset named "f)_Bristles-1_Details-opacity", this name might help to find were this one is mentioned in the kritarc.
Comment 6 David REVOY 2019-05-18 13:58:39 UTC
Here is another specimen, this time without even a 'save' or a 'stylus flip'; a third case happening in middle of shading the shoes of Pepper. I was hatching one side, I jump to the other side and the preset switch in mid-air.

Video 3:
========
https://www.peppercarrot.com/extras/videos/2019-05-17_random-preset-switch-bug_investigation-C.mp4
Comment 7 vanyossi 2019-05-18 14:02:16 UTC
Can we make it so we log only stylu id changes? it almost seems as it is registering a "new" stylus at random on those cases. Maybe there is something not ready and returnin a null somewhere??
Comment 8 Halla Rempt 2019-05-18 14:11:02 UTC
That should be doable... It would mean a special build, but it would worth it to get to the bottom of this issue.
Comment 9 Halla Rempt 2019-05-21 08:19:39 UTC
Okay, I've added logging of input device switching and preset switching in a branch, rempt/407659 . Could you please build that? The logs are in .local/share/krita.log, and it logs creating, loading, saving, closing images as well.
Comment 10 Halla Rempt 2019-05-21 16:45:24 UTC
Git commit 6327bc8433606592fffb8bb68fa9f6137609dd4d by Boudewijn Rempt.
Committed on 21/05/2019 at 16:44.
Pushed by rempt into branch 'rempt/407659'.

Add extra logging

M  +6    -0    libs/ui/kis_canvas_resource_provider.cpp
M  +4    -0    libs/ui/kis_paintop_box.cc

https://invent.kde.org/kde/krita/commit/6327bc8433606592fffb8bb68fa9f6137609dd4d
Comment 11 David REVOY 2019-05-22 09:07:09 UTC
Thank you for the branch Boud: I built it and could reproduce the bug while logging and screenrecording over 2h of painting and sketching since yesterday. I start to get used to see the log terminal with tail under my canvas ;-) The bug happens at 10:13:46 (timestamp of the log, sample pasted under), and can be seen in the video realtime. I'm not a specialist; but it looks like I have a ghost device named 3319598680403 who invited itself after flipping back my stylus from Eraser tip. Does my computer needs an exorcism? :D

Here is the video:
==================
https://www.peppercarrot.com/extras/videos/2019-05-22_random-preset-switch-bug_investigation-D.mp4 (1min - MP4)

Here is last 5min of krita.log:
===============================
22 May 2019 10:10:46 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:10:46 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:10:46 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/a)_Eraser_Soft.kpp
22 May 2019 10:10:50 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:10:50 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/a)_Eraser_Soft.kpp
22 May 2019 10:10:50 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:12:31 +0200: Converting from application/x-krita to application/x-krita. Location: /home/deevad/sketchbook/.019-05-22_anat-studies.kra-autosave.kra. Real location: /home/deevad/sketchbook/.019-05-22_anat-studies.kra-autosave.kra. Batchmode: 0. Configuration: none
22 May 2019 10:12:32 +0200: Completed saving /home/deevad/sketchbook/.019-05-22_anat-studies.kra-autosave.kra (mime: application/x-krita). Result: OK
22 May 2019 10:12:33 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:12:33 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:12:33 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/a)_Eraser_Soft.kpp
22 May 2019 10:12:36 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:12:36 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/a)_Eraser_Soft.kpp
22 May 2019 10:12:36 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:13:16 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:13:16 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:13:16 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/a)_Eraser_Soft.kpp
22 May 2019 10:13:19 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:13:19 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/a)_Eraser_Soft.kpp
22 May 2019 10:13:19 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:13:26 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:13:26 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:13:26 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/a)_Eraser_Soft.kpp
22 May 2019 10:13:31 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:13:31 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/a)_Eraser_Soft.kpp
22 May 2019 10:13:31 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:13:31 +0200: Changing input device to 2, 3319598680403
22 May 2019 10:13:31 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:13:31 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/f)_Bristles-1_Details-opacity.kpp
22 May 2019 10:13:46 +0200: Changing input device to 2, 3317451196755
22 May 2019 10:13:46 +0200: setPreviousPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/f)_Bristles-1_Details-opacity.kpp
22 May 2019 10:13:46 +0200: setPaintOpPreset:/home/deevad/.local/share/krita/paintoppresets/c)_Pencil-0_Thumb-sketch-33.kpp
22 May 2019 10:14:07 +0200: Saving Document /home/deevad/sketchbook/2019-05-22_anat-studies.kra as /home/deevad/sketchbook/2019-05-22_anat-studies.kra (mime: application/x-krita). 4166 * 2625 pixels, 3 layers.  101 frames, 24 framerate. Export configuration: No configuration
22 May 2019 10:14:07 +0200: Converting from application/x-krita to application/x-krita. Location: /home/deevad/sketchbook/2019-05-22_anat-studies.kra. Real location: /home/deevad/sketchbook/2019-05-22_anat-studies.kra. Batchmode: 0. Configuration: none

Setup:
======
- rempt/407659 branch (4.2.0-beta-git 2299e85) built from source on Kubuntu.
- Kernel Version: 4.15.0-50-generic
- Pretty Productname: Ubuntu 18.04.2 LTS (Kubuntu) with dependencies from packages 
- Cintiq13HD
- Nvidia proprietary driver, GeForce GTX 650 Ti/PCIe/SSE2
Comment 12 Halla Rempt 2019-05-23 09:23:41 UTC
Hah. The Qt documentation explicitly says the eraser and nib end of the stylus should have the same unique id: https://doc.qt.io/qt-5/qtabletevent.html#uniqueId -- and it doesn't. I guess we should stop using the tablet event's unique id completely :-(
Comment 13 Halla Rempt 2019-05-23 11:55:09 UTC
I've pushed a commit to the branch that disregards the unique id -- please test it when you've got some time :-)
Comment 14 David REVOY 2019-05-23 11:58:39 UTC
Thank you Boud! 
I'll compile and keep drawing/painting with this branch to give you feedback.
Comment 15 David REVOY 2019-05-24 17:43:46 UTC
Hi, I can't reproduce the bug so far, but it doesn't mean it disapeared: I drew yesterday three or four little sessions; between 30min and 40min for each (sketches). This afternoon I made a larger drawing, it took me two hours. No weird behavior observed and no switch (relaxing ^__^). 

I would like to keep drawing a couple hours more to rise the probability of telling this random switch thing is fixed. Can you cherry-pick this commit in the branch? https://cgit.kde.org/krita.git/commit/?id=974cf7b8eeedf07693bb50608eb4435703636b50 ; I have a lot of full transparent canvas when I open my files right now:)
Comment 16 Halla Rempt 2019-05-25 09:49:30 UTC
I've merged master to the test branch.
Comment 17 Halla Rempt 2019-05-27 09:48:15 UTC
Git commit 20cb1f86e1e129a64c111d2db3522013f534d83c by Boudewijn Rempt.
Committed on 27/05/2019 at 09:34.
Pushed by rempt into branch 'master'.

Do not use the stylus id to set the preset

Using the stylus' unique id to set the preset allowed users to
have different presets for e.g. an art pen and a normal stylus.

However, we are seeing random stylus id's for the same actual
stylus being reported, which means that this feature is completely
broken.
BACKPORT:krita/4.2

M  +4    -1    libs/flake/KoInputDevice.h
M  +3    -3    libs/ui/kis_paintop_box.cc
M  +2    -6    libs/ui/kis_paintop_box.h

https://invent.kde.org/kde/krita/commit/20cb1f86e1e129a64c111d2db3522013f534d83c
Comment 18 Halla Rempt 2019-05-27 09:48:40 UTC
Git commit c3b6c06698a33b8791c81a5dbc42427c57501225 by Boudewijn Rempt.
Committed on 27/05/2019 at 09:48.
Pushed by rempt into branch 'krita/4.2'.

Do not use the stylus id to set the preset

Using the stylus' unique id to set the preset allowed users to
have different presets for e.g. an art pen and a normal stylus.

However, we are seeing random stylus id's for the same actual
stylus being reported, which means that this feature is completely
broken.
BACKPORT:krita/4.2
(cherry picked from commit 20cb1f86e1e129a64c111d2db3522013f534d83c)

M  +4    -1    libs/flake/KoInputDevice.h
M  +3    -3    libs/ui/kis_paintop_box.cc
M  +2    -6    libs/ui/kis_paintop_box.h

https://invent.kde.org/kde/krita/commit/c3b6c06698a33b8791c81a5dbc42427c57501225
Comment 19 David REVOY 2019-05-27 10:07:27 UTC
Created attachment 120340 [details]
^ screenshot of the log, with ID switching marked (*403 VS *755), for archives

(I'm adding here what I wrote on IRC.) 

I had no more random preset switch after the patch. It is still hard to be 100% sure it disapeared because the random switch was random and rare (sometime could happen after 16min, sometime after 2 hours) but the log give me good hope it is resolved because the differents ID still happens rarely in it but now no more preset random switch. And also, I believe I drew around 10h more in total since the patch. 

❥ Thank you Boud for the help and investigation on my #1 annoyance while painting/drawing with Krita!