Browse Source

Fix ImageBrush crash when source bitmap gets disposed (#13506)

Nikita Tsukanov 2 years ago
parent
commit
e40d5d624c
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/Avalonia.Base/Media/Imaging/Bitmap.cs

+ 11 - 1
src/Avalonia.Base/Media/Imaging/Bitmap.cs

@@ -284,6 +284,16 @@ namespace Avalonia.Media.Imaging
             return AvaloniaLocator.Current.GetRequiredService<IPlatformRenderInterface>();
         }
 
-        IRef<IBitmapImpl> IImageBrushSource.Bitmap => PlatformImpl;
+        IRef<IBitmapImpl>? IImageBrushSource.Bitmap
+        {
+            get
+            {
+                // TODO12: We should probably make PlatformImpl to be nullable or make it possible to check
+                // and fix IRef<T> in general (right now Item is not nullable while it internally is)
+                if (PlatformImpl.Item == null!)
+                    return null;
+                return PlatformImpl;
+            }
+        }
     }
 }