Fix data loss after flattening the image from inside the group
ClosedPublic

Authored by tymond on Mar 7 2019, 1:55 PM.

Details

Summary

Before this patch, if the selected layer was inside of a group
and user requested flattening of the image, all layers
were deleted and no new layer with merged content appeared.
This commit makes the new layer with the merged content
be created and added to the layers stack.

BUG:405119

Test Plan
  • testing with test file from BUG:404200 both from inside

of the group (Layer 2) and outside of the group (Layer 1)

  • running unit tests added to the project in the patch
  • merging and unmerging layers in a complex file

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
tymond created this revision.Mar 7 2019, 1:55 PM
Restricted Application added a reviewer: Krita. · View Herald TranscriptMar 7 2019, 1:55 PM
Restricted Application added a project: Krita. · View Herald Transcript
tymond requested review of this revision.Mar 7 2019, 1:55 PM
rempt accepted this revision.Mar 7 2019, 2:04 PM
rempt added a subscriber: rempt.

I built and tested it, and yes, it fixes the issue.

libs/image/kis_layer_utils.cpp
757

Space between if and (

758

Please no spaces around ->

This revision is now accepted and ready to land.Mar 7 2019, 2:04 PM
tymond added a comment.Mar 7 2019, 2:26 PM

Actually it will probably break if the path from root to the putAfter node would be: N D D D N N D D D N (where D means "marked to be deleted" and N means otherwise). It won't happen with flattening, but since this function is used in other places, too, it's probably better to change it (to get the last ascendant instead of first), even though this case is a bit less common. (And the previous version of findPerfectParent() would cause the same data loss in this case).

rempt requested changes to this revision.Mar 7 2019, 2:27 PM

Okay... I hadn't considered that. Please go ahead?

This revision now requires changes to proceed.Mar 7 2019, 2:27 PM
tymond updated this revision to Diff 53378.Mar 7 2019, 5:13 PM

Fix multiple layer merging data loss

The previous version of the patch was still possible to break
in one specific case, not when flattening the image, but when
you merge several layers and select layers (including group layers)
from different parts of the path from root to the active layer.
This fix is to make sure it won't happen.

Another test file with instruction is in the bug report: https://bugs.kde.org/show_bug.cgi?id=405119

rempt accepted this revision.Mar 11 2019, 2:09 PM
This revision is now accepted and ready to land.Mar 11 2019, 2:09 PM
This revision was automatically updated to reflect the committed changes.