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.44k stars 538 forks source link

[BUG] <title>SKXamlCanvas in Winui3 bug after Visual studio Update #3031

Open chaibi-mustapha opened 6 days ago

chaibi-mustapha commented 6 days ago

Description

a debugger is attached but not configured to debug this exception

Code

Code Xaml :

<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="AppTest5.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:AppTest5"
    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">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <skia:SKXamlCanvas  x:FieldModifier="public"  x:Name="skXamlCanvas"  
                                  Width="1024"  Height="1024"
                                  HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"
                                  />
    </StackPanel>
</Window>

Code C# :

using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace AppTest5
{
    /// <summary>
    /// An empty window that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
        }

    }
}

Expected Behavior

No response

Actual Behavior

No response

Version of SkiaSharp

2.88.8 (Current)

Last Known Good Version of SkiaSharp

2.88.7 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

No response

Devices

No response

Relevant Screenshots

SkiaSharp Bug image

Relevant Log Output

No response

Code of Conduct

Mangepange commented 2 days ago

This is the same crash as when updating to WinUI 1.6.0 (#2999). It seems like the latest version of VS (17.11.5) updates the version of CsWinRT to 2.1.2. And from what I've seen, the issue is related to changes made in CsWinRT v2.1.1.

christoroth commented 2 days ago

Btw, this is also occurring in Windows based .Net Maui apps that use skia sharp. Updated Visual Studio and therefore also the windows sdk and my app started to crash but only in Windows (Android is ok).

Created a brand new Maui project and ran it from the default code that counts button clicks. Added SkiaSharp (remembering to add the UsesSkiaSharp call to MauiProgram.cs) and adding the SkCanvasView to the mainpage.xaml introduces the crash:

<skia:SKCanvasView x:Name="skCanvasView" WidthRequest="30" HeightRequest="50" BackgroundColor="Red" />

Tried the 2.88.8 SkiaSharp.Views.Maui.Controls package and also 3.0.0-preview.4.1 but same result from each

TopperDEL commented 18 hours ago

I have the same issue. From my point of view the only change between a working version and a crashing version is the switch from .Net SDK 8.0.402 to 8.0.403. It now crashes locally and with the version build in a Github Action. The only difference in the pipeline is the switch in the SDK-version. Don't know if this is really related, though. My app silently crashes without any exception if the SkXamlCanvas comes into view (this is an Uno app).

Update: The SDK-version does not seem to make a difference. I'm still investigating.

TopperDEL commented 18 hours ago

This seems to be the StackTrace:

bei System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   bei System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   bei WinRT.IWinRTObject.<IsInterfaceImplementedFallback>g__GetObjectReferenceViaVftbl|1_1(IObjectReference objRef, Type vftblType) in WinRT\IWinRTObject.cs: Zeile204
   bei WinRT.IWinRTObject.IsInterfaceImplementedFallback(RuntimeTypeHandle interfaceType, Boolean throwIfNotImplemented) in WinRT\IWinRTObject.cs: Zeile192
   bei WinRT.IWinRTObject.System.Runtime.InteropServices.IDynamicInterfaceCastable.IsInterfaceImplemented(RuntimeTypeHandle interfaceType, Boolean throwIfNotImplemented) in WinRT\IWinRTObject.cs: Zeile30
   bei WinRT.CastExtensions.As[TInterface](Object value) in WinRT\CastExtensions.cs: Zeile17
   bei SkiaSharp.Views.Windows.Utils.GetByteBuffer(IBuffer buffer)
   bei SkiaSharp.Views.Windows.WindowsExtensions.GetPixels(WriteableBitmap bitmap)
   bei SkiaSharp.Views.Windows.SKXamlCanvas.CreateBitmap(SKSizeI& unscaledSize, Single& dpi)
   bei SkiaSharp.Views.Windows.SKXamlCanvas.DoInvalidate()
   bei ABI.Microsoft.UI.Dispatching.DispatcherQueueHandler.Do_Abi_Invoke(IntPtr thisPtr) in ABI.Microsoft.UI.Dispatching\DispatcherQueueHandler.cs: Zeile123

image

 bei WinRT.ObjectReference`1.GetVtable(IntPtr thisPtr) in WinRT\ObjectReference.cs: Zeile130
   bei WinRT.ObjectReference`1..ctor(IntPtr thisPtr) in WinRT\ObjectReference.cs: Zeile31
   bei WinRT.ObjectReference`1.Attach(IntPtr& thisPtr, Guid iid) in WinRT\ObjectReference.cs: Zeile67
   bei WinRT.ObjectReference`1.TryAs(IObjectReference sourceRef, Guid iid, ObjectReference`1& objRef) in WinRT\ObjectReference.cs: Zeile155
   bei WinRT.IObjectReference.TryAs[T](Guid iid, ObjectReference`1& objRef) in WinRT\IObjectReference.cs: Zeile179
   bei WinRT.IObjectReference.As[T](Guid iid) in WinRT\IObjectReference.cs: Zeile140
   bei WinRT.IObjectReference.As[T]() in WinRT\IObjectReference.cs: Zeile134
   bei System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   bei System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

image

Hope that helps :)

christoroth commented 17 hours ago

3.0.0-preview-5.3 from package source https://pkgs.dev.azure.com/xamarin/public/_packaging/SkiaSharp/nuget/v3/index.json stopped the crashes for me in my test app so I have temporarily done the same in the app I'm developing until 3.0.0 is formally released (hopefully before my deadline!!).

TopperDEL commented 17 hours ago

Yes, just found out - this is the correct issue: https://github.com/mono/SkiaSharp/issues/2999