Skip to content

Commit

Permalink
Fix crash when undoing, redoing, and undoing a no-op resize operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 2, 2023
1 parent da84769 commit 6746b68
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class ClipCanvas_Change : ResizeBasedChangeBase
}
});

if (!bounds.HasValue)
if (!bounds.HasValue || bounds.Value.IsZeroOrNegativeArea || bounds.Value == new RectI(VecI.Zero, target.Size))
{
ignoreInUndo = true;
return new None();
Expand All @@ -48,12 +48,6 @@ internal class ClipCanvas_Change : ResizeBasedChangeBase
Resize(member.Mask, member.GuidValue, newBounds.Size, -newBounds.Pos, deletedMaskChunks);
});

if (newBounds.IsZeroOrNegativeArea)
{
ignoreInUndo = true;
return new None();
}

ignoreInUndo = false;
return new Size_ChangeInfo(newBounds.Size, target.VerticalSymmetryAxisX, target.HorizontalSymmetryAxisY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public override bool InitializeAndValidate(Document target)
return true;
}

/// <summary>
/// Notice: this commits image changes, you won't have a chance to revert or set ignoreInUndo to true
/// </summary>
protected virtual void Resize(ChunkyImage img, Guid memberGuid, VecI size, VecI offset, Dictionary<Guid, CommittedChunkStorage> deletedChunksDict)
{
img.EnqueueResize(size);
Expand All @@ -31,9 +34,6 @@ protected virtual void Resize(ChunkyImage img, Guid memberGuid, VecI size, VecI

public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document target)
{
if (target.Size == _originalSize)
return new None();

target.Size = _originalSize;
target.ForEveryMember((member) =>
{
Expand Down

0 comments on commit 6746b68

Please sign in to comment.