Bug 443306 - Masked brushes randomly stop working
Summary: Masked brushes randomly stop working
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Brush engines (show other bugs)
Version: git master (please specify the git hash!)
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Dmitry Kazakov
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2021-10-04 15:07 UTC by Lynx3d
Modified: 2021-10-05 14:35 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lynx3d 2021-10-04 15:07:51 UTC
SUMMARY

Various brushes randomly stop working and print console errors:

QSqlDatabasePrivate::database: requested database does not belong to the calling thread.
QSqlQuery::prepare: database not open
Could not prepare KisAllResourcesModel query for resource md5 QSqlError("", "Driver not loaded", "Driver not loaded")
Could not select "brushes" resources by md5 QSqlError("", "Driver not loaded", "Driver not loaded") QMap()

The thing they seem to have in common is a masked brush tip, so it's probably related to that.

STEPS TO REPRODUCE
1. Paint with a masked brush, here it happens most quickly with "m) RGBA 04 Impasto" and "m) RGBA 05 Impasto-details", but e.g. the "j) WaterC Spead *" brushes can cause it too
2. If nothing happened yet, try chaning some parameter like size, masked brush tip etc. and paint again
3. If it still didn't happen, try reloading the preset, paint again, and possibly repeat step 2

OBSERVED RESULT
Sooner or later, above error messages show up in console and brushes randomly  fail to paint correctly.

ADDITIONAL INFORMATION
Know to happen with master at e5f10d40b1c5a926e39dff3655b573d00ffef776 compiled on Ubuntu 20.04, Qt 5.15.3, aswell as nightly krita-5.0.0-beta1-7109bd4-x86_64.appimage.
The initial krita-5.0.0-beta1-x86_64.appimage seems not affected, so it must be something recent.
Comment 1 Dmitry Kazakov 2021-10-04 15:18:38 UTC
That is surely caused by my changes
Comment 2 Dmitry Kazakov 2021-10-05 14:34:56 UTC
Git commit ad830678eda51391b070c4f44c9c816a1411e451 by Dmitry Kazakov.
Committed on 05/10/2021 at 14:34.
Pushed by dkazakov into branch 'master'.

Fix threading issues when initializing brush caches in the background

Now the cache intialization is done in the following order:

1) Make a clone of the preset with all the dependent resource
   (so that we could pass it to a non-gui thread)

2) In a non-gui thread regenerate all the caches for this **cloned**
   preset and store them in KoResourceCacheStorage.

3) Check if the original preset hasn't changed since we have cloned it

4) If the original preset is still valid, upload the generated
   cache into it via setResourceCacheInterface()

M  +1    -7    libs/brush/kis_auto_brush.cpp
M  +1    -2    libs/brush/kis_auto_brush.h
M  +10   -6    libs/brush/kis_brush.cpp
M  +2    -4    libs/brush/kis_brush.h
M  +4    -20   libs/brush/kis_imagepipe_brush.cpp
M  +1    -2    libs/brush/kis_imagepipe_brush.h
M  +15   -46   libs/image/brushengine/kis_paintop_preset.cpp
M  +20   -14   libs/image/brushengine/kis_paintop_preset.h
M  +32   -5    libs/image/brushengine/kis_paintop_settings.cpp
M  +7    -4    libs/image/brushengine/kis_paintop_settings.h
M  +3    -0    libs/resources/CMakeLists.txt
A  +21   -0    libs/resources/KoResourceCacheInterface.cpp     [License: GPL(v2.0+)]
A  +31   -0    libs/resources/KoResourceCacheInterface.h     [License: GPL(v2.0+)]
A  +25   -0    libs/resources/KoResourceCachePrefixedStorageWrapper.cpp     [License: GPL(v2.0+)]
A  +26   -0    libs/resources/KoResourceCachePrefixedStorageWrapper.h     [License: GPL(v2.0+)]
A  +38   -0    libs/resources/KoResourceCacheStorage.cpp     [License: GPL(v2.0+)]
A  +27   -0    libs/resources/KoResourceCacheStorage.h     [License: GPL(v2.0+)]
M  +67   -18   libs/ui/KisPresetShadowUpdater.cpp
M  +5    -0    libs/ui/KisPresetShadowUpdater.h
M  +30   -11   plugins/paintops/libpaintop/kis_brush_based_paintop_settings.cpp
M  +2    -2    plugins/paintops/libpaintop/kis_brush_based_paintop_settings.h

https://invent.kde.org/graphics/krita/commit/ad830678eda51391b070c4f44c9c816a1411e451
Comment 3 Dmitry Kazakov 2021-10-05 14:35:26 UTC
Git commit 9bd53486d0d41becd923ca04d5163b9b0ceeef3b by Dmitry Kazakov.
Committed on 05/10/2021 at 14:35.
Pushed by dkazakov into branch 'krita/5.0'.

Fix threading issues when initializing brush caches in the background

Now the cache intialization is done in the following order:

1) Make a clone of the preset with all the dependent resource
   (so that we could pass it to a non-gui thread)

2) In a non-gui thread regenerate all the caches for this **cloned**
   preset and store them in KoResourceCacheStorage.

3) Check if the original preset hasn't changed since we have cloned it

4) If the original preset is still valid, upload the generated
   cache into it via setResourceCacheInterface()

M  +1    -7    libs/brush/kis_auto_brush.cpp
M  +1    -2    libs/brush/kis_auto_brush.h
M  +10   -6    libs/brush/kis_brush.cpp
M  +2    -4    libs/brush/kis_brush.h
M  +4    -20   libs/brush/kis_imagepipe_brush.cpp
M  +1    -2    libs/brush/kis_imagepipe_brush.h
M  +15   -46   libs/image/brushengine/kis_paintop_preset.cpp
M  +20   -14   libs/image/brushengine/kis_paintop_preset.h
M  +32   -5    libs/image/brushengine/kis_paintop_settings.cpp
M  +7    -4    libs/image/brushengine/kis_paintop_settings.h
M  +3    -0    libs/resources/CMakeLists.txt
A  +21   -0    libs/resources/KoResourceCacheInterface.cpp     [License: GPL(v2.0+)]
A  +31   -0    libs/resources/KoResourceCacheInterface.h     [License: GPL(v2.0+)]
A  +25   -0    libs/resources/KoResourceCachePrefixedStorageWrapper.cpp     [License: GPL(v2.0+)]
A  +26   -0    libs/resources/KoResourceCachePrefixedStorageWrapper.h     [License: GPL(v2.0+)]
A  +38   -0    libs/resources/KoResourceCacheStorage.cpp     [License: GPL(v2.0+)]
A  +27   -0    libs/resources/KoResourceCacheStorage.h     [License: GPL(v2.0+)]
M  +67   -18   libs/ui/KisPresetShadowUpdater.cpp
M  +5    -0    libs/ui/KisPresetShadowUpdater.h
M  +30   -11   plugins/paintops/libpaintop/kis_brush_based_paintop_settings.cpp
M  +2    -2    plugins/paintops/libpaintop/kis_brush_based_paintop_settings.h

https://invent.kde.org/graphics/krita/commit/9bd53486d0d41becd923ca04d5163b9b0ceeef3b