Mapsui icon indicating copy to clipboard operation
Mapsui copied to clipboard

Maps do not render for Uno 6 apps using Skia Rendering

Open kazo0 opened this issue 5 months ago • 4 comments

Mapsui Version 5.0.0-beta.17

Mapsui Platform Uno Desktop/WASM/Android/iOS using Uno 6.0.130 and Skia Rendering

Describe the bug As of Uno 6, you can use the unified skia rendering engine for all supported platforms.

The maps render on the net9.0-desktop target but with the following error:

mapsuiuno6 Error: 0 : No canvas was assigned. This is unexpected. Exception: System.Exception: No canvas was assigned. This is unexpected. at Mapsui.UI.WinUI.MapControl.InvalidateCanvas() at Mapsui.Rendering.RenderController.InvalidateLoopAsync() at Mapsui.Extensions.Catch.<>c__DisplayClass3_0.<<TaskRun>b__0>d.MoveNext()

For all other platforms, the maps do not display and fail with the following error:

System.NotSupportedException: SKSwapChainPanel is not supported for Skia based platforms

Full stacktrace:

fail: Uno.UI.Dispatching.NativeDispatcher[0] NativeDispatcher unhandled exception System.NotSupportedException: SKSwapChainPanel is not supported for Skia based platforms at SkiaSharp.Views.Windows.SKSwapChainPanel..ctor() in /_/source/SkiaSharp.Views.Uno/SkiaSharp.Views.Uno.WinUI.Skia/SKSwapChainPanel.Skia.cs:line 22 at Mapsui.UI.WinUI.MapControl.CreateGpuRenderTarget() at Mapsui.UI.WinUI.MapControl..ctor() at mapsuiuno6.MainPage.InitializeComponent() in X:\src\TestApps\mapsuiuno6\mapsuiuno6\obj\Debug\net9.0-browserwasm\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGenerator\MainPage_cd9fc8bdd233f377a45a8704c1af1a88.cs:line 57 at mapsuiuno6.MainPage..ctor() in X:\src\TestApps\mapsuiuno6\mapsuiuno6\MainPage.xaml.cs:line 13 at mapsuiuno6.MetadataBuilder_621.CreateInstance() in X:\src\TestApps\mapsuiuno6\mapsuiuno6\obj\Debug\net9.0-browserwasm\Uno.UI.SourceGenerators\Uno.UI.SourceGenerators.BindableTypeProviders.BindableTypeProvidersSourceGenerator\BindableMetadata.g.cs:line 22717 at Microsoft.UI.Xaml.Controls.Frame.CreatePageInstance(Type sourcePageType) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:line 178 at DirectUI.NavigationCache.LoadContent(String descriptor) in C:\a\1\s\src\Uno.UI\UI\Xaml\Navigation\NavigationCache.mux.cs:line 85 at DirectUI.NavigationCache.GetContent(PageStackEntry pPageStackEntry) in C:\a\1\s\src\Uno.UI\UI\Xaml\Navigation\NavigationCache.mux.cs:line 55 at Microsoft.UI.Xaml.Controls.Frame.PerformNavigation() in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.partial.mux.cs:line 411 at Microsoft.UI.Xaml.Controls.Frame.StartNavigation() in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.partial.mux.cs:line 342 at Microsoft.UI.Xaml.Controls.Frame.NavigateWithTransitionInfoImpl(Type sourcePageType, Object parameter, NavigationTransitionInfo navigationTransitionInfo) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.partial.mux.cs:line 304 at Microsoft.UI.Xaml.Controls.Frame.NavigateImpl(Type sourcePageType, Object parameter) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.partial.mux.cs:line 259 at Microsoft.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter) in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:line 110 at mapsuiuno6.App.OnLaunched(LaunchActivatedEventArgs args) in X:\src\TestApps\mapsuiuno6\mapsuiuno6\App.xaml.cs:line 45 at Microsoft.UI.Xaml.Application.InvokeOnLaunched() in C:\a\1\s\src\Uno.UI\UI\Xaml\Application.skia.cs:line 237 at Uno.UI.Dispatching.NativeDispatcher.RunAction(NativeDispatcher dispatcher, Action action) in C:\a\1\s\src\Uno.UI.Dispatching\Native\NativeDispatcher.cs:line 153

To Reproduce Steps to reproduce the behavior:

  1. Launch the attached sample app for any platform other than net9.0-desktop
  2. Note the error in the logs

Expected behavior Maps should render

Screenshots

Image

Additional context

Relevant Uno docs for consideration and implications on control libraries for Skia Rendering: https://platform.uno/docs/articles/features/using-skia-rendering.html#implications-for-iosandroid-class-libraries

Sample app

mapsuiuno6.zip

kazo0 avatar Jun 15 '25 13:06 kazo0

I'll investigate using uno 6.0 as target

inforithmics avatar Jun 15 '25 22:06 inforithmics

Pull request https://github.com/Mapsui/Mapsui/pull/3031

inforithmics avatar Jun 15 '25 23:06 inforithmics

Awesome! Let me know if I can help in any way!

kazo0 avatar Jun 16 '25 00:06 kazo0

@kazo0 You could try 5.0.0-beta.18 which contains @inforithmics's fix.

pauldendulk avatar Jun 17 '25 11:06 pauldendulk

I am getting the same error on beta.18 (Android, Uno SDK 6.0.146)

Image

mikernet avatar Jul 08 '25 23:07 mikernet

@kazo0 It should be possible for this library to support both uno skia and native renderers, should it not? In which case it should not use the SkiaRenderer feature. What is the solution to the SKSwapChainPanel issue in that case? LiveCharts2, for example, renders to a skia surface but it works on both skia and native renderers for me.

mikernet avatar Jul 09 '25 11:07 mikernet

SKSwapChainPanel is not supported in Skia rendering mode at this time, because there's no swap chain to use.

The best path forward for skia targets would be to use the Uno provided SKCanvasElement as it uses hardware acceleration which SkiaSharp's SKXamlCanvas does not have. We might end up updating SKXamlCanvas and SKSwapChainPanel to use SKCanvasElement, but it would force a significant upgrade to the uno dependency that is not sufficiently warranted at this time.

SKCanvasElement was introduced in Uno 5.5 for Skia targets. Note that for now, we do not have an API that provides a way to know if generic code is running using the Skia renderer, but it's possible to determine that it is by using the Assembly.Load("Uno.UI.Runtime.Skia") is not null condition.

jeromelaban avatar Jul 09 '25 20:07 jeromelaban

Thanks for the PR https://github.com/Mapsui/Mapsui/pull/3054 I had trouble getting it to build locally and the build on the build server also fails.

Based on that one I created this PR which builds locally https://github.com/Mapsui/Mapsui/pull/3056 (and the rendering seems pretty fast!).

@ramezgerges @jeromelaban @kazo0 Some questions:

  • I now use net9-desktop, which others do I need. This is the list we had before: net9.0;net9.0-ios;net9.0-maccatalyst;net9.0-android;net9.0-browserwasm;net9.0-windows10.0.19041;net9.0-desktop
  • Do I need to add a nuget reference to Uno.WinUI.Graphics2DSK, or should that come from the SDK (something was mentioned in a warning).
  • Is now use SKCanvasElement. I understand that in wasm and android (and also ios?) native rendering is still supported. Do I need another canvas for that scenario, or do i need to treat it in a difference way? or just the same SKCanvasElement?

pauldendulk avatar Jul 14 '25 15:07 pauldendulk

@pauldendulk Thanks for following up. I already have some updates locally that fix the build error and do some refactoring to avoid the many #ifs that were there, so I guess the other PR can be closed.

However, as things currently stand, the MapsUI uno project sets the SkiaRenderer UnoFeature which means that MapControl should not work when a user app doesn't have SkiaRenderer enabled, so it breaks when a user app wants to use native rendering. This is the way it is even on master, but the PR doesn't address this. Now without SkiaRenderer, we also lose the SKCanvasElement type, so that's a problem. The SKCanvasElement type needs to be present even without SkiaRenderer even if it can't function (i.e. the type should be there but it should crash at runtime). We're hoping to add these Uno-side changes before this PR is finalized that fix that issue. We're facing some minor delays, but it should be done soon.

Now for your questions:

  • You actually need to use the net9.0 TFM and remove any platform-specific TFMs. This builds against a cross-platform subset of Uno's API set and should work everywhere. As mentioned above, SKCanvasElement will need to be part of this "cross-platform" subset even if it can't work except when skia rendering is enabled.
  • You will also need to remove SkiaRenderer as mentioned previously and instead add the Skia UnoFeature which adds skia package references (e.g. SkiaSharp and SkiaSharp.Views) without changing the rendering mode. Uno.WinUI.Graphics2DSK should also be included by the SDK when the Skia UnoFeature is enabled, but that is not yet the case (this is part of the changes we intend to make).
  • SKCanvasElement does not work with native rendering. SKCanvasElement should only be used when skia rendering is enabled (similar to how it's done in this PR)

Let me know if you need any additional clarification. Thanks.

ramezgerges avatar Jul 14 '25 16:07 ramezgerges

@ramezgerges Thanks a lot, all clear.

BTW, currently we have TFMs for net9 and net8. I can image it is hard to keep supporting net8 with such big changes going on. This could just be removed. So, don't do anything complicated to keep supporting net8.

Also, we have a problem with the Uno.Resizetizer. There is a version override in the Mapsui.Samples.Uno.WinUI.csproj and it fail randomly in some of the build (perhaps also related to having both net8 and net9 supported).

pauldendulk avatar Jul 15 '25 06:07 pauldendulk

@pauldendulk Could we open a new issue for the Resizetizer problem with the available details?

ramezgerges avatar Jul 15 '25 15:07 ramezgerges

@pauldendulk Could we open a new issue for the Resizetizer problem with the available details?

Yes, I don't expect you to to fix the resizetizer in the PR, it is just something I wanted to mention to the uno people, and it could be something that you run into trying to get the PR to build.

pauldendulk avatar Jul 19 '25 11:07 pauldendulk

I am getting a blank white canvas on Android/Skia wherever a map should be on latest beta.22. Working on Android/non-Skia and Desktop. Can't test iOS at the moment.

Should I open a new issue?

mikernet avatar Sep 10 '25 19:09 mikernet

Yes, please do

pauldendulk avatar Sep 11 '25 05:09 pauldendulk