Browse Source

Slightly change try catch in DocumentViewModel.PickColor

Equbuxu 3 years ago
parent
commit
c25d08bb71
1 changed files with 24 additions and 24 deletions
  1. 24 24
      src/PixiEditorPrototype/ViewModels/DocumentViewModel.cs

+ 24 - 24
src/PixiEditorPrototype/ViewModels/DocumentViewModel.cs

@@ -525,33 +525,33 @@ internal class DocumentViewModel : INotifyPropertyChanged
     }
     }
 
 
     public SKColor PickColor(VecI pos, bool fromAllLayers)
     public SKColor PickColor(VecI pos, bool fromAllLayers)
-    {
-        // it might've been a better idea to implement this function
-        // via a passthrough action to avoid all the try catches
-        if (fromAllLayers)
-        {
-            VecI chunkPos = OperationHelper.GetChunkPos(pos, ChunkyImage.FullChunkSize); 
-            return ChunkRenderer.MergeWholeStructure(chunkPos, ChunkResolution.Full, Helpers.Tracker.Document.StructureRoot)
-                .Match<SKColor>(
-                    (Chunk chunk) =>
-                    {
-                        VecI posOnChunk = pos - chunkPos * ChunkyImage.FullChunkSize;
-                        var color = chunk.Surface.GetSRGBPixel(posOnChunk);
-                        chunk.Dispose();
-                        return color;
-                    },
-                    _ => SKColors.Transparent
-                );
-        }
-        
-        if (SelectedStructureMember is not LayerViewModel layerVm)
-            return SKColors.Transparent;
-        var maybeMember = Helpers.Tracker.Document.FindMember(layerVm.GuidValue);
-        if (maybeMember is not IReadOnlyLayer layer)
-            return SKColors.Transparent;
+    { 
         // there is a tiny chance that the image might get disposed by another thread
         // there is a tiny chance that the image might get disposed by another thread
         try
         try
         {
         {
+            // it might've been a better idea to implement this function
+            // via a passthrough action to avoid all the try catches
+            if (fromAllLayers)
+            {
+                VecI chunkPos = OperationHelper.GetChunkPos(pos, ChunkyImage.FullChunkSize);
+                    return ChunkRenderer.MergeWholeStructure(chunkPos, ChunkResolution.Full, Helpers.Tracker.Document.StructureRoot)
+                        .Match<SKColor>(
+                            (Chunk chunk) =>
+                            {
+                                VecI posOnChunk = pos - chunkPos * ChunkyImage.FullChunkSize;
+                                var color = chunk.Surface.GetSRGBPixel(posOnChunk);
+                                chunk.Dispose();
+                                return color;
+                            },
+                            _ => SKColors.Transparent
+                        );
+            }
+            
+            if (SelectedStructureMember is not LayerViewModel layerVm)
+                return SKColors.Transparent;
+            var maybeMember = Helpers.Tracker.Document.FindMember(layerVm.GuidValue);
+            if (maybeMember is not IReadOnlyLayer layer)
+                return SKColors.Transparent;
             return layer.LayerImage.GetMostUpToDatePixel(pos);
             return layer.LayerImage.GetMostUpToDatePixel(pos);
         }
         }
         catch (ObjectDisposedException)
         catch (ObjectDisposedException)