Bug 445390

Summary: Layer styles duplicate bundled patterns and gradients
Product: [Applications] krita Reporter: vanyossi <ghevan>
Component: Resource ManagementAssignee: Krita Bugs <krita-bugs-null>
Status: CONFIRMED ---    
Severity: normal CC: eoinoneill1991
Priority: NOR    
Version First Reported In: 5.0.0-beta2   
Target Milestone: ---   
Platform: Other   
OS: Other   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description vanyossi 2021-11-12 19:21:29 UTC
I've been testing layer styles and I noticed some patterns appeared twice even if the file with the layer style was not open.

STEPS TO REPRODUCE
1. Apply a pattern overlay layer style: Maze_line.png and apply and save the file
2. Relaunch Krita (At this point the resource manager shows the pattern only once as supposed.)
3. Open the file with the layer style
4. The pattern will be shown twice as expected but not listed in as a layer resource but instead as a bundle resource.
5. Close file and relaunch: Pattern is duplicated since.

I've managed to by, selecting the duplicated pattern and resaving/relaunching, to duplicate the same resource in several bundles. i.e. the same pattern shown listed in krita3.bundled and krita4.bundle. The duplicated patterns are stored in <kritaResources>/<bundlename>_modified/patterns . As a note: I was only able to make "09b_drawed-CrossedLines.png" be duplicated 2 times. once as a krita3.bundle_modified and once as krita4, as this resource is on both bundles.

As a note I also tested this in MR1146 (https://invent.kde.org/graphics/krita/-/merge_requests/1146) and got the same result.
Comment 1 Eoin O'Neill 2021-11-17 04:10:35 UTC
Yes this is definitely occurring. 

Interestingly, the new (erroneous) database entry has the following as the filename:

`751bdf15-6ddd-46d6-bf9d-bac02b5d4628.0001.pat`

This probably means that somewhere in the embedded resource loading, there's a erroneous call that is using the md5 as the file name. This is probably fine when dealing with resources that aren't already present in the database, but we should try to load existing resources and compare md5 hash values first to allow for reuse wherever possible.
Comment 2 Bug Janitor Service 2021-12-08 10:36:09 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1211
Comment 3 Dmitry Kazakov 2021-12-08 10:57:32 UTC
Git commit 98502d4f1dae30780cc6121274ef0a43c5408057 by Dmitry Kazakov.
Committed on 08/12/2021 at 10:55.
Pushed by dkazakov into branch 'master'.

Fix layer styles dialog breaking the global Fg->Bg gradient

It looks like we don't create copies of the required resources
when putting them in the local storage. Whether we should do that
or not is a rather disputable topic (because it can cause
efficiency problems). So right now we should just be careful when
baking the gradients, and make copies explicitly.

The patch is also partially related to the problem mentioned in
the bug 445390 (though it doesn't fix it):
Related: bug 446623
(cherry picked from commit 0cdacdf4d5d60703b652a36465df5e04a3d35da8)

M  +17   -5    libs/image/kis_psd_layer_style.cpp
M  +6    -0    libs/resources/KisLocalStrokeResources.cpp
M  +1    -0    libs/resources/KisLocalStrokeResources.h

https://invent.kde.org/graphics/krita/commit/98502d4f1dae30780cc6121274ef0a43c5408057
Comment 4 Dmitry Kazakov 2021-12-08 10:59:31 UTC
Git commit 7d4a3f67356fec178e6cadd734ede1414c72a987 by Dmitry Kazakov.
Committed on 08/12/2021 at 10:58.
Pushed by dkazakov into branch 'krita/5.0'.

Fix layer styles dialog breaking the global Fg->Bg gradient

It looks like we don't create copies of the required resources
when putting them in the local storage. Whether we should do that
or not is a rather disputable topic (because it can cause
efficiency problems). So right now we should just be careful when
baking the gradients, and make copies explicitly.

The patch is also partially related to the problem mentioned in
the bug 445390 (though it doesn't fix it):
Related: bug 446623

M  +17   -5    libs/image/kis_psd_layer_style.cpp
M  +6    -0    libs/resources/KisLocalStrokeResources.cpp
M  +1    -0    libs/resources/KisLocalStrokeResources.h

https://invent.kde.org/graphics/krita/commit/7d4a3f67356fec178e6cadd734ede1414c72a987