Bug 441605 - Safe assert on reading a file with a layer style
Summary: Safe assert on reading a file with a layer style
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Resource Management (show other bugs)
Version: git master (please specify the git hash!)
Platform: Mint (Ubuntu based) Linux
: NOR normal
Target Milestone: ---
Assignee: amyspark
URL:
Keywords:
Depends on:
Blocks: 464700
  Show dependency treegraph
 
Reported: 2021-08-27 13:40 UTC by Tiar
Modified: 2023-01-28 01:31 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tiar 2021-08-27 13:40:11 UTC
SUMMARY
I'm not sure yet if it's any file or just that particular one.


STEPS TO REPRODUCE
1. Open the file in Krita.

OBSERVED RESULT
Output in console (and the safe assert box):
SAFE ASSERT (krita): "!localResources.contains(KoResourceSP())" in file /home/tymon/kritadev/krita/libs/resources/KisLocalStrokeResources.cpp, line 78
Could not copy PSDResourceBlock "Could not read resource block: no bytes left."
Could not copy PSDResourceBlock "Could not read resource block: no bytes left."
Could not copy PSDResourceBlock "Could not read resource block: no bytes left."
Could not copy PSDResourceBlock "Could not read resource block: no bytes left."

EXPECTED RESULT
No safe assert.


NOTE:
source of the test file: https://dribbble.com/shots/1129892-King-Free-Photoshop-Layer-Style


SOFTWARE/OS VERSIONS
Krita

 Version: 5.0.0-prealpha (git bad2b20)
 Languages: en_US, en, en_US, en, en_US, en, pl_PL, pl, pl_PL, pl
 Hidpi: true

Qt

  Version (compiled): 5.11.1
  Version (loaded): 5.11.1
Comment 1 amyspark 2021-10-18 00:05:01 UTC
Cannot reproduce on 5.1.0-prealpha 804225bc51, which I guess is because of my reworked loading of PSD resource blocks. However, I did find that layer styles are never set as valid, so the end result is the same-- layer styles present but not loaded.

Assigning to myself.
Comment 2 Bug Janitor Service 2021-10-18 01:27:23 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1101
Comment 3 Halla Rempt 2021-10-18 11:12:05 UTC
Git commit 6039f5b45aad719625e22de38afdfd6432141ee1 by Halla Rempt, on behalf of L. E. Segovia.
Committed on 18/10/2021 at 11:11.
Pushed by rempt into branch 'master'.

psd: mark read layer styles as valid

M  +1    -0    plugins/impex/psd/psd_loader.cpp

https://invent.kde.org/graphics/krita/commit/6039f5b45aad719625e22de38afdfd6432141ee1
Comment 4 amyspark 2021-10-21 13:11:06 UTC
Git commit 0e13f684c3e0c14b461a678ae0a61804ef0dccab by L. E. Segovia.
Committed on 21/10/2021 at 13:07.
Pushed by lsegovia into branch 'master'.

KisPSDLayerStyle: ensure users of saveToDevice assert

M  +2    -3    libs/image/kis_psd_layer_style.cpp

https://invent.kde.org/graphics/krita/commit/0e13f684c3e0c14b461a678ae0a61804ef0dccab
Comment 5 amyspark 2021-10-21 13:11:14 UTC
Git commit 885e62a63383e5117a158b3c6601c910ce21b2e6 by L. E. Segovia.
Committed on 21/10/2021 at 13:07.
Pushed by lsegovia into branch 'master'.

KisAslLayerStyleSerializer: fix layer-local gradients load

In 2d426ac0b57ad8595a01b0c82d18633e4ec6060b, @dkazakov refactored the
load so that layer styles would insert their resources on global storage
instead of keeping them in their local stashes. However, this did not
take in account that layers can also have locally defined e.g.
gradients. These will not be found if the resource interface is
overriden because they are resident on the root layer's
localStrokeStorage.

Upon a complete review of the code, the true reason for this failure
lied not only in the (in)validity of the layer style, which I fixed in a
previous commit, but also on the fact that gradients and patterns are
uploaded *before* they are read (!!), in the embedded pattern
registration loop.

This commit fixes that by moving the two upload loops to inside the
layer style deserialization, and making sure they upload only missing
resources (to avoid accidentally quadratic behaviour).
CCMAIL: dimula73@gmail.com
CCMAIL: tamtamy.tymona@gmail.com

M  +4    -0    libs/image/kis_asl_layer_style_serializer.cpp
M  +19   -16   plugins/impex/psd/psd_loader.cpp

https://invent.kde.org/graphics/krita/commit/885e62a63383e5117a158b3c6601c910ce21b2e6
Comment 6 amyspark 2021-10-21 13:13:01 UTC
Git commit 04c87c696878503fb359ab5e4ff20a65c83db58e by L. E. Segovia.
Committed on 21/10/2021 at 13:11.
Pushed by lsegovia into branch 'krita/5.0'.

KisPSDLayerStyle: ensure users of saveToDevice assert
(cherry picked from commit 0e13f684c3e0c14b461a678ae0a61804ef0dccab)

M  +2    -3    libs/image/kis_psd_layer_style.cpp

https://invent.kde.org/graphics/krita/commit/04c87c696878503fb359ab5e4ff20a65c83db58e
Comment 7 amyspark 2021-10-21 13:13:09 UTC
Git commit 222f7814482ca797148b757566dc153fcc255d5a by L. E. Segovia.
Committed on 21/10/2021 at 13:12.
Pushed by lsegovia into branch 'krita/5.0'.

KisAslLayerStyleSerializer: fix layer-local gradients load

In 2d426ac0b57ad8595a01b0c82d18633e4ec6060b, @dkazakov refactored the
load so that layer styles would insert their resources on global storage
instead of keeping them in their local stashes. However, this did not
take in account that layers can also have locally defined e.g.
gradients. These will not be found if the resource interface is
overriden because they are resident on the root layer's
localStrokeStorage.

Upon a complete review of the code, the true reason for this failure
lied not only in the (in)validity of the layer style, which I fixed in a
previous commit, but also on the fact that gradients and patterns are
uploaded *before* they are read (!!), in the embedded pattern
registration loop.

This commit fixes that by moving the two upload loops to inside the
layer style deserialization, and making sure they upload only missing
resources (to avoid accidentally quadratic behaviour).
CCMAIL: dimula73@gmail.com
CCMAIL: tamtamy.tymona@gmail.com
(cherry picked from commit 885e62a63383e5117a158b3c6601c910ce21b2e6)

M  +4    -0    libs/image/kis_asl_layer_style_serializer.cpp
M  +20   -16   plugins/impex/psd/psd_loader.cpp

https://invent.kde.org/graphics/krita/commit/222f7814482ca797148b757566dc153fcc255d5a
Comment 8 amyspark 2023-01-28 01:29:56 UTC
Git commit 973acffa8a24c640e3a3c95007f99dfe4b4f5f48 by L. E. Segovia.
Committed on 28/01/2023 at 01:29.
Pushed by lsegovia into branch 'master'.

KisAslLayerStyleSerializer: fix layer-local patterns

This is the counterpart of bug 441605, we only found this one out
because in 464700 Wolthera injects a placeholder pattern, which in turn
was never put into global storage.

For the sake of completionism, I've added several safe asserts in the
path that the nullptr makes, so that we get breakpointable warnings for
missing resources in the future.
Related: bug 464700
CCMAIL:dimula73@gmail.com
CCMAIL:tamtamy.tymona@gmail.com

M  +15   -5    libs/image/kis_asl_layer_style_serializer.cpp
M  +2    -0    libs/image/layerstyles/kis_ls_utils.cpp
M  +5    -0    libs/resources/KisLocalStrokeResources.cpp
M  +6    -0    libs/resources/KisRequiredResourcesOperators.cpp
M  +1    -0    libs/resources/KoResourceLoadResult.cpp
M  +8    -0    plugins/impex/psd/psd_loader.cpp

https://invent.kde.org/graphics/krita/commit/973acffa8a24c640e3a3c95007f99dfe4b4f5f48
Comment 9 amyspark 2023-01-28 01:31:48 UTC
Git commit 8e83efca125a263dc993cf92e89c290f9339efe3 by L. E. Segovia.
Committed on 28/01/2023 at 01:31.
Pushed by lsegovia into branch 'krita/5.1'.

KisAslLayerStyleSerializer: fix layer-local patterns

This is the counterpart of bug 441605, we only found this one out
because in 464700 Wolthera injects a placeholder pattern, which in turn
was never put into global storage.

For the sake of completionism, I've added several safe asserts in the
path that the nullptr makes, so that we get breakpointable warnings for
missing resources in the future.
Related: bug 464700
CCMAIL:dimula73@gmail.com
CCMAIL:tamtamy.tymona@gmail.com
(cherry picked from commit 973acffa8a24c640e3a3c95007f99dfe4b4f5f48)

M  +15   -5    libs/image/kis_asl_layer_style_serializer.cpp
M  +2    -0    libs/image/layerstyles/kis_ls_utils.cpp
M  +5    -0    libs/resources/KisLocalStrokeResources.cpp
M  +6    -0    libs/resources/KisRequiredResourcesOperators.cpp
M  +1    -0    libs/resources/KoResourceLoadResult.cpp
M  +8    -0    plugins/impex/psd/psd_loader.cpp

https://invent.kde.org/graphics/krita/commit/8e83efca125a263dc993cf92e89c290f9339efe3