浏览代码

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

Nikita Tsukanov 2 年之前
父节点
当前提交
e40d5d624c
共有 1 个文件被更改,包括 11 次插入1 次删除
  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>();
             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;
+            }
+        }
     }
     }
 }
 }