From e40d5d624cb6e3eb54743b4046d69ebe69e56b5a Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Mon, 6 Nov 2023 15:15:35 +0300 Subject: [PATCH] Fix ImageBrush crash when source bitmap gets disposed (#13506) --- src/Avalonia.Base/Media/Imaging/Bitmap.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Media/Imaging/Bitmap.cs b/src/Avalonia.Base/Media/Imaging/Bitmap.cs index 4ddf0eb322..fc6dfb1f19 100644 --- a/src/Avalonia.Base/Media/Imaging/Bitmap.cs +++ b/src/Avalonia.Base/Media/Imaging/Bitmap.cs @@ -284,6 +284,16 @@ namespace Avalonia.Media.Imaging return AvaloniaLocator.Current.GetRequiredService(); } - IRef IImageBrushSource.Bitmap => PlatformImpl; + IRef? IImageBrushSource.Bitmap + { + get + { + // TODO12: We should probably make PlatformImpl to be nullable or make it possible to check + // and fix IRef in general (right now Item is not nullable while it internally is) + if (PlatformImpl.Item == null!) + return null; + return PlatformImpl; + } + } } }