Skip to content

Commit

Permalink
Fix mask deletion crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed May 29, 2023
1 parent eae4ce4 commit 3147a88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/PixiEditor/Models/Rendering/MemberPreviewUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
namespace PixiEditor.Models.Rendering;
internal class MemberPreviewUpdater
{
private const float smoothingThreshold = 1.5f;

private readonly DocumentViewModel doc;
private readonly DocumentInternalParts internals;

Expand All @@ -32,10 +34,9 @@ internal class MemberPreviewUpdater
private Dictionary<Guid, AffectedArea> mainPreviewAreasAccumulator = new();
private Dictionary<Guid, AffectedArea> maskPreviewAreasAccumulator = new();

private const float smoothingThreshold = 1.5f;
private static readonly Paint SmoothReplacingPaint = new() { BlendMode = BlendMode.Src, FilterQuality = FilterQuality.Medium, IsAntiAliased = true };
private static readonly Paint ReplacingPaint = new() { BlendMode = BlendMode.Src };
private static readonly Paint ClearPaint = new() { BlendMode = BlendMode.Src, Color = PixiEditor.DrawingApi.Core.ColorsImpl.Colors.Transparent };
private static readonly Paint ClearPaint = new() { BlendMode = BlendMode.Src, Color = DrawingApi.Core.ColorsImpl.Colors.Transparent };

public MemberPreviewUpdater(DocumentViewModel doc, DocumentInternalParts internals)
{
Expand Down Expand Up @@ -175,6 +176,12 @@ private static void AddAreas(Dictionary<Guid, AffectedArea> from, Dictionary<Gui
if (member is null)
continue;

if (forMasks && member.Mask is null)
{
newPreviewBitmapSizes.Add(guid, null);
continue;
}

RectI? tightBounds = GetOrFindMemberTightBounds(member, area, forMasks);
RectI? maybeLastBounds = targetLastBounds.TryGetValue(guid, out RectI lastBounds) ? lastBounds : null;
if (tightBounds == maybeLastBounds)
Expand Down Expand Up @@ -214,7 +221,7 @@ private void RecreatePreviewBitmaps(
{
if (member.PreviewBitmap is not null && member.PreviewBitmap.PixelWidth == newSize.Value.previewSize.X && member.PreviewBitmap.PixelHeight == newSize.Value.previewSize.Y)
{
member.PreviewSurface.Canvas.Clear();
member.PreviewSurface!.Canvas.Clear();
}
else
{
Expand Down Expand Up @@ -272,6 +279,7 @@ private void RecreatePreviewBitmaps(
{
IReadOnlyLayer layer => FindLayerTightBounds(layer, forMask),
IReadOnlyFolder folder => FindFolderTightBounds(folder, forMask),
_ => throw new ArgumentOutOfRangeException()
};
}

Expand All @@ -283,7 +291,7 @@ private void RecreatePreviewBitmaps(
if (layer.Mask is null && forMask)
throw new InvalidOperationException();

IReadOnlyChunkyImage targetImage = forMask ? layer.Mask : layer.LayerImage;
IReadOnlyChunkyImage targetImage = forMask ? layer.Mask! : layer.LayerImage;
return FindImageTightBounds(targetImage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public float OpacityBindable
public StructureMemberSelectionType Selection { get; set; }

public const int PreviewSize = 48;
public WriteableBitmap PreviewBitmap { get; set; }
public DrawingSurface PreviewSurface { get; set; }
public WriteableBitmap? PreviewBitmap { get; set; }
public DrawingSurface? PreviewSurface { get; set; }

public WriteableBitmap? MaskPreviewBitmap { get; set; }
public DrawingSurface? MaskPreviewSurface { get; set; }
Expand Down

0 comments on commit 3147a88

Please sign in to comment.