Browse Source

Fix edge case crash when cropping an image. Handle exceptions in CropResizer and log debug data.

Ruben 5 months ago
parent
commit
3c4e0f46f9
1 changed files with 12 additions and 4 deletions
  1. 12 4
      src/PicView.Avalonia/Crop/CropResizer.cs

+ 12 - 4
src/PicView.Avalonia/Crop/CropResizer.cs

@@ -4,6 +4,7 @@ using Avalonia.Input;
 using PicView.Avalonia.Input;
 using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.Views.UC;
+using PicView.Core.DebugTools;
 
 namespace PicView.Avalonia.Crop;
 
@@ -98,10 +99,17 @@ public static class CropResizer
         ApplyBoundsConstraints(ref newX, ref newY, ref newWidth, ref newHeight, vm.ImageWidth, vm.ImageHeight);
         
         // Update the view model
-        vm.SelectionX = Convert.ToInt32(newX);
-        vm.SelectionY = Convert.ToInt32(newY);
-        vm.SelectionWidth = Convert.ToInt32(newWidth);
-        vm.SelectionHeight = Convert.ToInt32(newHeight);
+        try
+        {
+            vm.SelectionX = Convert.ToInt32(newX);
+            vm.SelectionY = Convert.ToInt32(newY);
+            vm.SelectionWidth = Convert.ToInt32(newWidth);
+            vm.SelectionHeight = Convert.ToInt32(newHeight);
+        }
+        catch (Exception exception)
+        {
+            DebugHelper.LogDebug(nameof(CropResizer), nameof(Resize), exception);
+        }
         
         // Update the rectangle position on canvas
         Canvas.SetLeft(control.MainRectangle, newX);