0

I am accessing the SKCanvas of an SKSurface in my PaintSurface function. This function fires and I get the error: System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

private async void cnv_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{

        SKSurface surface = e.Surface;
        SKCanvas canvas = surface.Canvas; 

        **SkiaSharp.Extended.Svg.SKSvg svg = new SkiaSharp.Extended.Svg.SKSvg();
        svg.Load(await GetStream());**

        using (SKPaint paint = new SKPaint())
        {
            canvas.Clear(Colors.Black.ToSKColor());  //here is the error
            canvas.DrawPicture(svg.Picture, paint);
        }
}

private static async Task<Stream> GetStream()
{
    StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("car.svg");

    var inputStream = await file.OpenReadAsync();
    return inputStream.AsStreamForRead();
}```
  • I have testing with official [code sample](https://github.com/xamarin/xamarin-forms-samples/blob/master/SkiaSharpForms/Demos/Demos/SkiaSharpFormsDemos/Basics/BitmapDissolvePage.xaml.cs#L41), Unfortunately, we can't reproduce this issue. please provide [mcve] for testing, I will edit base on your demo. – Nico Zhu Nov 17 '20 at 07:05
  • I have edited the code to show where I get the stream – DarthSerpical Nov 18 '20 at 09:05
  • I'm afraid you can't use windows storage api in Xamarin Form project directly, I have test with `var s = assembly.GetManifestResourceStream("SkiaSharpFormsDemos.ross.svg")` . I could load svg correctly. – Nico Zhu Nov 18 '20 at 09:21
  • OK - thanks. Can it be used in a UWP project? – DarthSerpical Nov 18 '20 at 11:49
  • Yep, I have not tested it, but I think SkiaSharp could use in pure uwp project. And you could also use win2d to render svg picture. – Nico Zhu Nov 18 '20 at 13:30

0 Answers0