Bug 478520 - Inconsistent undo may lead to data loss when creating a layer above global selection mask
Summary: Inconsistent undo may lead to data loss when creating a layer above global se...
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Layer Stack (other bugs)
Version First Reported In: 5.2.2
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-14 19:18 UTC by paleh
Modified: 2024-01-11 10:22 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description paleh 2023-12-14 19:18:03 UTC
STEPS TO REPRODUCE
0. "Show global selection mask" must be active.
1. Create a selection.
2. Create a new layer above the global selection mask (this happens naturally when the user calls "New Layer from Visible" for example)
3. Draw some strokes on this new layer.
4. Press Undo enough times to get to before step 1 (before the selection existed)
5. Press Redo.

OBSERVED RESULT
Pressing Redo any further doesn't bring back the layer created in step 2. Thus, all work done on that layer in steps 2-3 is lost.

EXPECTED RESULT
It is possible to redo all the way to the last action done in step 3.

SOFTWARE/OS VERSIONS
Linux: Ubuntu 22.04
Qt Version: 5.15.7
Appimage

ADDITIONAL INFORMATION
This was present in 5.1.5 and is present on master (git-1fc417ae3e)
Comment 1 Freya Lupen 2023-12-14 23:46:47 UTC
Confirmed. Some safe asserts are logged during this:
> SAFE ASSERT (krita): "!m_d->parent || !parent" in file /libs/image/kis_paint_device.cc, line 1195
> SAFE ASSERT (krita): "!aboveThis || aboveThis->parent().data() == this" in file /libs/image/kis_node.cpp, line 471
This might have the same cause as bug 478519.
Comment 2 Dmitry Kazakov 2024-01-11 10:20:41 UTC
Hi, paleh!

Thank you for the report. The bug is indeed has the same cause as bug 478519. I have a fix for that bug that is going to be merge soon :)

*** This bug has been marked as a duplicate of bug 478519 ***
Comment 3 Dmitry Kazakov 2024-01-11 10:22:11 UTC
Git commit 45491cdab843c617e35983534fafbf81ad900f0a by Dmitry Kazakov.
Committed on 11/01/2024 at 11:22.
Pushed by dkazakov into branch 'master'.

Fix inconsistent undo/redo of select/deselect/reselect actions

Before the patch, the global selection actions operated with a
raw selection object, not with a selection mask. It caused issues,
when the user manually converted/moved the global selection mask
into another position.

The patch changes this behavior and makes the selection commands
operate with the entire selection mask, which makes operations
consistent.
Related: bug 478519

M  +1    -1    krita/kritamenu.action
M  +2    -0    libs/image/CMakeLists.txt
A  +24   -0    libs/image/KisImageGlobalSelectionManagementInterface.h     [License: GPL(v2.0+)]
A  +39   -0    libs/image/commands/KisChangeDeselectedMaskCommand.cpp     [License: GPL(v2.0+)]
A  +31   -0    libs/image/commands/KisChangeDeselectedMaskCommand.h     [License: GPL(v2.0+)]
A  +21   -0    libs/image/commands/KisNotifySelectionChangedCommand.cpp     [License: GPL(v2.0+)]
A  +24   -0    libs/image/commands/KisNotifySelectionChangedCommand.h     [License: GPL(v2.0+)]
M  +18   -18   libs/image/commands/kis_deselect_global_selection_command.cpp
M  +3    -6    libs/image/commands/kis_deselect_global_selection_command.h
M  +25   -25   libs/image/commands/kis_reselect_global_selection_command.cpp
M  +3    -6    libs/image/commands/kis_reselect_global_selection_command.h
M  +36   -11   libs/image/commands/kis_set_global_selection_command.cpp
M  +3    -3    libs/image/commands/kis_set_global_selection_command.h
M  +22   -44   libs/image/kis_image.cc
M  +7    -26   libs/image/kis_image.h
M  +11   -7    libs/image/tests/kis_image_test.cpp
M  +4    -2    libs/libkis/Document.cpp
M  +1    -0    libs/ui/kis_action.h
M  +4    -0    libs/ui/kis_action_manager.cpp
M  +30   -9    libs/ui/kis_selection_manager.cc
M  +1    -0    libs/ui/kis_selection_manager.h

https://invent.kde.org/graphics/krita/-/commit/45491cdab843c617e35983534fafbf81ad900f0a