mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.14k stars 522 forks source link

Using SKSwapChainPanel nuget package V3-Preview 2.1 in WinUI3 Throws an Exception: AccessViolationException #2803

Open AmitParmar2005 opened 1 month ago

AmitParmar2005 commented 1 month ago

Description

Hi Friends,

First of all thank you so much for porting SKSwapChainPanel to WinUI3. I have been waiting for it for very long time.

To test new functionalities, I created a simple program which uses SKSwapChainPanel. I have installed Skiasharp.Views.WinUI (3.0.0-preview 2.1) nuget package. But, when I run the application, I get System.AccessViolationException: 'Attempted to read or write protected memory.

image

Seems, I have installed all required packages.

image

I have also build and install angle with vcpkg. Without any luck.

Can somebody please help me what I am missing here? Please let me know if you want me to upload project.

Thanks and Regards, Amit

Code

The best way to share code for larger projects is a link to a GitHub repository: https://github.com/user/repo/tree/bug-123

But, you can also share a short block of code here:

// some C# code here

You can also share some XAML:

<!-- xaml code here -->

<Window x:Class="WINUI_SkiaSharp_SKSwap_Test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:WINUI_SkiaSharp_SKSwap_Test" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:skia="using:SkiaSharp.Views.Windows" mc:Ignorable="d">

<Grid Name="mygrid">
    <StackPanel>
        <skia:SKSwapChainPanel Name="canvas" Height="200" Width="200"/>
    </StackPanel>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
    </StackPanel>
</Grid>

Expected Behavior

I should not throw an expception

Actual Behavior

Throws an exception

Version of SkiaSharp

3.x (Alpha)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 10

Devices

Windows 10 Laptop

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

mattleibow commented 1 month ago

You should not install any other ANGLE library - it is included in the package.

Let me know if removing ANGLE and rebuilding after deleting the bin/obj fixes this.

TopperDEL commented 1 month ago

I'm running into the same problem. All I did was: create a new WinUI-project (in this case a Uno-App), add the SkiaSharp.Views.Uno.WinUI-package and the following code:

xmlns:skia="using:SkiaSharp.Views.Windows"
<skia:SKSwapChainPanel PaintSurface="SKSwapChainPanel_PaintSurface" Height="200" Width="200"/>

Then I get the exact same error as mentioned above.

AmitParmar2005 commented 1 month ago

I was able to make it running. Dont install Uno package. Install WinUI Package. Here's the screenshot. Please let me know if you want me to upload entire project.

image

TopperDEL commented 1 month ago

Thanks @AmitParmar2005 - but that does not seem to help in my case. I don't get the SKSwapChainPanel to work on Uno. I tried adding SkiaSharp itself, switchting to preview 2.1 (like you have above) - but none works. I always get the error above as soon as I add an SKSwapChainPanel-Control to my page.

AmitParmar2005 commented 1 month ago

Try the attached zip file. Its very simple working sample. Let me know if you still have any issues.

WinUI3_SKSwap_Test.zip

TopperDEL commented 1 month ago

That works here, too. But I don't get it to work together with Uno-platform.

AmitParmar2005 commented 1 month ago

I am not sure about Uno-Platform. I never worked on it. I will check it out and get back to you.

TopperDEL commented 1 month ago

Awesome, thanks!