diff --git a/source/SkiaSharp.Views/SkiaSharp.Views.Apple/SKCGSurfaceFactory.cs b/source/SkiaSharp.Views/SkiaSharp.Views.Apple/SKCGSurfaceFactory.cs index fe027073ec..11cf42450d 100644 --- a/source/SkiaSharp.Views/SkiaSharp.Views.Apple/SKCGSurfaceFactory.cs +++ b/source/SkiaSharp.Views/SkiaSharp.Views.Apple/SKCGSurfaceFactory.cs @@ -47,6 +47,13 @@ public SKSurface CreateSurface(CGRect contentsBounds, nfloat scale, out SKImageI if (bitmapData == null) { bitmapData = NSMutableData.FromLength(info.BytesSize); + + // in case allocation has failed + if (bitmapData == null) { + info.Width = info.Height = 0; + return null; + } + dataProvider = new CGDataProvider(bitmapData.MutableBytes, info.BytesSize, Dummy); void Dummy(IntPtr data)