Bug 397836

Summary: Undo/Redo Bug when merging a layer that has been `Clone`d
Product: [Applications] krita Reporter: tusooa <tusooa>
Component: Layer StackAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: critical CC: freebox64
Priority: NOR    
Version: 4.1.1   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Video

Description tusooa 2018-08-24 13:29:37 UTC
Hi,

I am facing problems with undo/redo and the Clone Layer. Here is the steps to reproduce the bug:

1. Create a document in Krita.
2. Add a Paint Layer (assuming its name is Layer 2).
3. Add a Paint Layer (assuming its name is Layer 3) above Layer 3.
4. Paint something on both Layer 2 and Layer 3.
5. Add a Clone Layer of Layer 2 (assuming its name is Layer 4).
6. Move the content of Layer 4 so that it can be seen easily.
7. In the `Layers` Docker, move Layer 4 to someplace below Layer 2.
8. Merge Layer 3 with Layer 2. Note that Layer 4 has become a Paint Layer.
9. Undo. Layer 2 (the merged layer) has *gone*; Layer 4 reappears to be a Clone Layer.
10. Redo. Layer 2 does not come back. Layer 4 is again a Paint Layer.

The correct behavior, in my opinion, is:

In Step 8, Layer 4 continues to be a Clone Layer of the merged Layer.
In Step 9, the layers restore their original state before the merge.
In Step 10, Layer 3 and 2 are merged again, and Layer 4 continues to be a Clone Layer of the merged Layer.

PS: If you add some Masks to the Clone Layer, after merging some of them are gone.
Comment 1 mvowada 2018-08-25 17:53:54 UTC
Confirming using 4.2.0-pre-alpha (git 04931e4) on Ubuntu 14.04:

    1. merge with a layer that has a clone (Paint with Paint layers) 
    2. CTRL+Z (Undo)

Both the Paint layers will disappear from the stack.
By doing Redo they wont't reappear. Thanks for the detailed report
Comment 2 mvowada 2018-08-25 18:02:49 UTC
Changing the importance to "Critical" since it causes data loss.
Comment 3 mvowada 2018-08-29 08:36:24 UTC
Created attachment 114671 [details]
Video

Example of data loss occurring when doing "Merge with Layer below (CTRL+E)" with only 1 layer highlighted + "Undo (CTRL+Z)"
Comment 4 tusooa 2019-04-07 15:07:25 UTC
(In reply to mvowada from comment #3)
> Created attachment 114671 [details]
> Video
> 
> Example of data loss occurring when doing "Merge with Layer below (CTRL+E)"
> with only 1 layer highlighted + "Undo (CTRL+Z)"

I've put up my proposed fix for review: https://phabricator.kde.org/D20314
Comment 5 Dmitry Kazakov 2019-04-20 12:31:21 UTC
Git commit 2239e9550e351df412f75137069b15bc7f040fa6 by Dmitry Kazakov, on behalf of Tusooa Zhu.
Committed on 20/04/2019 at 12:27.
Pushed by dkazakov into branch 'master'.

Fix undo merging a layer that is cloned

1) Add two paint layers. Assume they are "Layer 1" and "Layer 2," from bottom to top.
2) Add a clone layer copying from "Layer 1." Assume the clone is called "Layer 3."
3) Move "Layer 3" below "Layer 1."
4) In the layer docker, click on "Layer 1."
5) Hold Ctrl, click on "Layer 2."
6) Right click, then select "Remove Layer."

Expected: Layer 1 and Layer 2 are removed. Layer 3 turns into a Paint Layer.

7) Undo.

Expected: Layer 1 and Layer 2 are restored. Layer 3 goes back into a Clone Layer.
Reviewers: #krita, dkazakov
Reviewed By: #krita, dkazakov
Subscribers: dkazakov
Tags: #krita
Differential Revision: https://phabricator.kde.org/D20314

M  +1    -1    libs/image/commands/kis_image_layer_remove_command_impl.cpp

https://invent.kde.org/kde/krita/commit/2239e9550e351df412f75137069b15bc7f040fa6