Bug 490843

Summary: No layer is active after switching between views, except for the last opened view
Product: [Applications] krita Reporter: Tyson Tan <tysontanx>
Component: Layer StackAssignee: Dmitry Kazakov <dimula73>
Status: RESOLVED FIXED    
Severity: normal CC: halla, info, reinhart.schultz, silver.bullet
Priority: NOR Keywords: regression, release_blocker
Version: nightly build (please specify the git hash!)   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Tyson Tan 2024-07-26 09:00:29 UTC
When opening multiple images all at once, no layer is active except for the last image. The user can't do anything until they select one layer. Tested with latest nightlies. Noticed since 2024-07-25.

Procedure to reproduce:
1) Prepare 2 images, let's call them A/B for now;
2) Drag these 2 images together into Krita's window;
3) Let's presume image A is opened first, and B opened last;

Result:
1) Only Image B (the last one opened) has an active layer by default.
2) Switch to Image A -- it has no active layer -- and thus cannot be edited.

Expected:
Every image that opened together should have an active layer.

I consider this a bug, because Krita would normally make sure one layer is active for us. This is an inconsistent and confusing behavior.
Comment 1 Halla Rempt 2024-07-26 09:22:44 UTC
I first tested with the files as arguments, and there it works now, but I can confirm the issue with drag & drop.
Comment 2 Tyson Tan 2024-07-26 11:57:08 UTC
Also happens to Main Menu -> File -> Open dialogue with multiple files selected.
Comment 3 Tyson Tan 2024-07-28 02:43:03 UTC
I have done some more testing today, and there were new findings.

This bug has nothing to do with "opening files". It happens when "switching between views that has multiple layers".

Procedure to reproduce:
1) Open 2 images with multiple layers, let's call the first image A, and the last image B;
2) Switch to image A, select a layer;
3) Switch to image B, then back to A;

Result:
Image A now has no active layer.

Expected result:
Image A should retain its active layer.

Exception:
If Image A has only 1 layer, that layer will still be active after switching views.
Comment 4 Tyson Tan 2024-07-29 02:27:56 UTC
When drag-and-dropping multiple single layer PNGs into Krita's window, the original report is still valid.
Comment 5 Ralek Kolemios 2024-07-30 06:00:32 UTC
> Procedure to reproduce:
> 1) Open 2 images with multiple layers, let's call the first image A, and the
> last image B;
> 2) Switch to image A, select a layer;
> 3) Switch to image B, then back to A;
> 
> Result:
> Image A now has no active layer.

To be more specific about what exactly causes it and hopefully help find a fix, a good summary of the exact cause can be described like so:

If you switch away from a document and then switch back, the image will have no active layer unless the last selected layer was also the last created layer.

Doesn't matter how it was created. pasted, shortcut, duplicating.
It can be any layer type, like filter, or clone, or vector, or mask.
It can be renamed
It can be moved around the layer stack anywhere.
But if it's not the one selected when you switch documents, nothing will be selected when you switch back.
Comment 6 Dmitry Kazakov 2024-07-31 08:47:31 UTC
*** Bug 490636 has been marked as a duplicate of this bug. ***
Comment 7 Dmitry Kazakov 2024-07-31 09:10:31 UTC
Git commit 3b5891816897a868630d3570f044df275bc7a197 by Dmitry Kazakov.
Committed on 31/07/2024 at 09:08.
Pushed by dkazakov into branch 'master'.

Fix layer activation issue when opening multiple documents

... and switching between them.

KisNodeManager may emit node change signal right inside setCanvas()
call, which may be received by LayerBox **before** it gto received
its own setCanvas() call. This workaround just checks if the node-to-
be-activated actually belongs to the current image or not.

Ideally, we should make the active layer code a bit more straight-forward
and ensure that there is only one source of truth. But I'm not sure how
to do that right now. Perhaps, during the QML rewite?

M  +14   -0    plugins/dockers/layerdocker/LayerBox.cpp

https://invent.kde.org/graphics/krita/-/commit/3b5891816897a868630d3570f044df275bc7a197
Comment 8 Dmitry Kazakov 2024-07-31 09:11:47 UTC
Git commit 580a313c993972442b42289c55cb9dae8c98dba6 by Dmitry Kazakov.
Committed on 31/07/2024 at 09:11.
Pushed by dkazakov into branch 'krita/5.2'.

Fix layer activation issue when opening multiple documents

... and switching between them.

KisNodeManager may emit node change signal right inside setCanvas()
call, which may be received by LayerBox **before** it gto received
its own setCanvas() call. This workaround just checks if the node-to-
be-activated actually belongs to the current image or not.

Ideally, we should make the active layer code a bit more straight-forward
and ensure that there is only one source of truth. But I'm not sure how
to do that right now. Perhaps, during the QML rewite?

M  +14   -0    plugins/dockers/layerdocker/LayerBox.cpp

https://invent.kde.org/graphics/krita/-/commit/580a313c993972442b42289c55cb9dae8c98dba6
Comment 9 Tyson Tan 2024-08-01 00:59:18 UTC
Thank you, Dmitry!
Comment 10 Halla Rempt 2024-09-05 12:24:45 UTC
*** Bug 492671 has been marked as a duplicate of this bug. ***