Browse Source

Fix a crash related to Zoombox.Scale == 0 and hopefully prevent the scale from ever going out of bounds

Equbuxu 1 year ago
parent
commit
e6593ad099

+ 1 - 1
src/ChunkyImageLib/Operations/OperationHelper.cs

@@ -234,7 +234,7 @@ public static class OperationHelper
 
 
     public static HashSet<VecI> FindChunksTouchingRectangle(RectI rect, int chunkSize)
     public static HashSet<VecI> FindChunksTouchingRectangle(RectI rect, int chunkSize)
     {
     {
-        if (rect.Width > chunkSize * 40 * 20 || rect.Height > chunkSize * 40 * 20)
+        if (rect.Width > chunkSize * 40 * 20 || rect.Height > chunkSize * 40 * 20 || rect.IsZeroOrNegativeArea)
             return new HashSet<VecI>();
             return new HashSet<VecI>();
 
 
         VecI min = GetChunkPos(rect.TopLeft, chunkSize);
         VecI min = GetChunkPos(rect.TopLeft, chunkSize);

+ 1 - 1
src/PixiEditor.DrawingApi.Core/Numerics/RectI.cs

@@ -80,7 +80,7 @@ public struct RectI : IEquatable<RectI>
     public int Width { readonly get => right - left; set => right = left + value; }
     public int Width { readonly get => right - left; set => right = left + value; }
     public int Height { readonly get => bottom - top; set => bottom = top + value; }
     public int Height { readonly get => bottom - top; set => bottom = top + value; }
     public readonly bool IsZeroArea => left == right || top == bottom;
     public readonly bool IsZeroArea => left == right || top == bottom;
-    public readonly bool IsZeroOrNegativeArea => left >= right || top >= bottom;
+    public readonly bool IsZeroOrNegativeArea => left >= right || top >= bottom || Width < 0 || Height < 0; // checking Width and Height too as they can overflow in large rectangles 
 
 
     public RectI()
     public RectI()
     {
     {

+ 1 - 1
src/PixiEditor.Zoombox/Operations/ZoomDragOperation.cs

@@ -33,7 +33,7 @@ internal class ZoomDragOperation : IDragOperation
         double deltaX = curScreenPos.X - screenScaleOrigin.X;
         double deltaX = curScreenPos.X - screenScaleOrigin.X;
         double deltaPower = deltaX / 10.0;
         double deltaPower = deltaX / 10.0;
 
 
-        parent.Scale = originalScale * Math.Pow(Zoombox.ScaleFactor, deltaPower);
+        parent.Scale = Math.Clamp(originalScale * Math.Pow(Zoombox.ScaleFactor, deltaPower), parent.MinScale, Zoombox.MaxScale);
 
 
         VecD shiftedOrigin = parent.ToZoomboxSpace(screenScaleOrigin);
         VecD shiftedOrigin = parent.ToZoomboxSpace(screenScaleOrigin);
         parent.Center += scaleOrigin - shiftedOrigin;
         parent.Center += scaleOrigin - shiftedOrigin;

+ 1 - 1
src/PixiEditor.Zoombox/Zoombox.xaml.cs

@@ -284,7 +284,7 @@ public partial class Zoombox : ContentControl, INotifyPropertyChanged
         Angle = 0;
         Angle = 0;
         FlipX = false;
         FlipX = false;
         FlipY = false;
         FlipY = false;
-        Scale = 1 / scaleFactor;
+        Scale = Math.Clamp(1 / scaleFactor, MinScale, MaxScale);
         Center = newSize / 2;
         Center = newSize / 2;
     }
     }