You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Skia] BitmapSource.SetSource throws NullReferenceException for a stream Skia can't decode (6.x) #25549
On 6.x with the Skia renderer, BitmapSource.SetSource and SetSourceAsync throw a NullReferenceException when the stream holds data SkiaSharp can't decode: HEIC, AVIF, PDF or corrupt bytes. ImageFailed is never raised.
BitmapSource.skia.cs reads the size up front with SKCodec.Create(stream).Info, and SKCodec.Create returns null for such data. WriteableBitmap.SetSource fails the same way when it decodes the stream into its pixel buffer (SKImage.FromEncodedData(...) then .Info, in WriteableBitmap.skia.cs).
On WebAssembly the exception also blocks the browser decode that the stream load tries before Skia's, so a stream in a format the browser can decode, such as AVIF in Chrome or HEIC in Safari, can't be loaded either.
Expected behavior 🎯
SetSource doesn't throw, PixelWidth and PixelHeight stay 0, and the load raises ImageFailed, as on WinUI and on master. On WebAssembly the browser decode gets its chance first.
How to reproduce it (as minimally and precisely as possible) 🔬
varbitmap=newBitmapImage();bitmap.ImageFailed+=(s,e)=>Debug.WriteLine($"ImageFailed: {e.ErrorMessage}");// Any bytes Skia can't decode: a .heic, .avif or .pdf file, or garbage.varbytes=newbyte[]{1,2,3,4};bitmap.SetSource(newMemoryStream(bytes).AsRandomAccessStream());// NullReferenceException
Workaround 🛠️
Catch the exception around SetSource/SetSourceAsync and treat it as a failed image. On WebAssembly, to let the browser decode a format Skia doesn't support, save the stream to a file and set UriSource to its ms-appdata:/// URI instead: the URI path doesn't read the size up front.
Uno.Sdk 6.7.30 (Uno.UI 6.7.135), seen on Skia desktop (Windows), WebAssembly and Android. Also seen on servicing/6.8 (5efcb98), on Skia desktop and WebAssembly.
master is not affected: there, BitmapSource and WriteableBitmap decode through ImageEncoderDecoder.Current.TryDecode and leave the size and pixels alone when it fails.
Activity