Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] On iOS, with .NET 9.0 Preview 2 and 3 and SkiaSharp 3.0 Preview 2.1 / 3.1, SKGLView corrupts SkiaSharp memory and stops SkiaSharp from functioning #2840

Open
1 task done
janne-hmp opened this issue Apr 19, 2024 · 8 comments
Labels

Comments

@janne-hmp
Copy link

janne-hmp commented Apr 19, 2024

Description

My game GnollHack has several SKCanvasViews and a few SKGLViews, and they all work well in SkiaSharp 2.88.8 (Xamarin). However, on iOS in SkiaSharp 3.0 Preview 2.1 / 3.1 with .NET MAUI 9.0 Preview 2 or 3, SkiaSharp's memory gets corrupted, and it stops drawing the canvases / draws a black canvas only / draws garbage or partial images.

This seems to be a problem when SKGLViews are used in the app. When you change them to SKCanvasView, the problem seems to disappear.

Code

https://github.com/hyvanmielenpelit/GnollHack

Expected Behavior

Game and SKGLView works as in Xamarin 2.88.8 on iOS.

Actual Behavior

After a minute or so, especially after opening many pages and showing and hiding layouts, SkiaSharp's memory gets corrupted and it stops drawing or draws garbage when using SKGLView on iOS.

Version of SkiaSharp

3.x (Alpha)

Last Known Good Version of SkiaSharp

2.88.8 in Xamarin (Android works, too)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

iOS

Platform / Operating System Version

iOS 17.4.3

Devices

iPad 11,7

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@janne-hmp janne-hmp changed the title [BUG] On iOS, SkiaSharp 3.0 Preview 3 sometimes corrupts memory and stops functioning [BUG] On iOS, SkiaSharp 3.0 Preview 3.1 corrupts memory and stops functioning Apr 19, 2024
@janne-hmp janne-hmp changed the title [BUG] On iOS, SkiaSharp 3.0 Preview 3.1 corrupts memory and stops functioning [BUG] On iOS, .NET 9.0 Preview 3 with SkiaSharp 3.0 Preview 2.1 / 3.1 corrupts memory and stops functioning Apr 19, 2024
@janne-hmp
Copy link
Author

This may be because there's (still) something wrong with .NET MAUI 9.0 Preview 3 iOS workload download, and perhaps it downloads (a non-functioning) Preview 4 prematurely instead of the correct workload version. @rolfbjarne Any update there?

@janne-hmp
Copy link
Author

I tested this again today with a clean install, and I can confirm just changing to .NET 9.0 Preview 3 is sufficient to make SkiaSharp to stop working after a while on iOS, while working with SkiaSharp 3.0 Preview 2.1 (and other libraries exactly like in .NET 9.0 Preview 2).

@janne-hmp
Copy link
Author

janne-hmp commented Apr 20, 2024

This seems to be an issue also in .NET 9.0 Preview 2, and not sure at all where this is coming from on iOS.

@janne-hmp janne-hmp changed the title [BUG] On iOS, .NET 9.0 Preview 3 with SkiaSharp 3.0 Preview 2.1 / 3.1 corrupts memory and stops functioning [BUG] On iOS, .NET 9.0 Preview 2 and 3 with SkiaSharp 3.0 Preview 2.1 / 3.1 corrupts memory and stops functioning Apr 20, 2024
@janne-hmp
Copy link
Author

I tested whether this is caused by special iOS features like animations etc., but none of them are the culprit. Happens in all combinations of .NET 9.0 Preview 2 / 3 and SkiaSharp 3.0 Preview 2.1 and 3.1. Always only on iOS. @mattleibow Any idea how to work out what is causing the problem?

It is always the SKGLView in the menu screen that stops working first (though it is on the same page--as an (in)visible grid--as the main game) and then SKCanvasView that draws the background for another page. And then finally the other SKGLViews and some SKCanvasViews. But this may be dependent on that these are the screens that I test and use the most.

@janne-hmp
Copy link
Author

janne-hmp commented Apr 20, 2024

Touch events seem to still work, but all canvases are drawing just black in the end, apart from a a few small ones inside custom controls that still seem to work. Happens consistently after playing for a while. Memory consumption seems to be reasonable at 30MB, so that is not a problem. And happens also with default gpu cache size, so changing that is mostly likely not a problem. And also confirmed that Android does work fine.

@janne-hmp
Copy link
Author

I changed now SKGLViews to SKCanvasViews and the problems seems to have been fixed. @mattleibow Can you investigate why SKGLView on iOS is corrupting the memory?

@janne-hmp
Copy link
Author

I added one more observation here, which some luck could be interrelated this memory corruption problem: #2842 ; SKGLView seems to hinder the speed of .NET layout, making the page with SKGLView look wobbly for the couple of first 100s of milliseconds. This has been a problem on iOS at least since 2.80.3, but I realized now for the first time that this is related to SKGLView being present on the page.

@janne-hmp janne-hmp changed the title [BUG] On iOS, .NET 9.0 Preview 2 and 3 with SkiaSharp 3.0 Preview 2.1 / 3.1 corrupts memory and stops functioning [BUG] On iOS, with .NET 9.0 Preview 2 and 3 and SkiaSharp 3.0 Preview 2.1 / 3.1, SKGLView corrupts SkiaSharp memory and stops SkiaSharp from functioning Apr 20, 2024
@janne-hmp
Copy link
Author

janne-hmp commented May 23, 2024

@mattleibow With .NET MAUI 9.0 Preview 4, things seem to be now a bit more stable on iOS in SkiaSharp 3.0 Preview 3.1. I still managed to get the menu canvas to stop redrawing itself by doing a lot of random stuff in the UI first, but it does not seem to draw garbage anymore, just not redrawing itself. Also, the menu canvas was missing canvas.Flush() from the end of its PaintSurface, which I now added. This may have further contributed to stability, as I couldn't make the menu canvas stop working anymore with a short test, but this is subject to further testing naturally. Not sure if a missing Flush() could have caused things to malfunction with SKGLCanvas earlier?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant