-
Notifications
You must be signed in to change notification settings - Fork 540
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
[iOS, 3.0 Preview 3.1] SkiaSharp's memory becomes corrupted and it stops to function in .NET 9.0 Preview 6 #2840
Comments
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? |
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). |
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. |
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. |
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. |
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? |
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. |
@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 |
Maybe fixed with Preview 5 and Flush. |
This seems to be still problem in 9.0 Preview 6 in MAUI. Xamarin iOS with SKGLView works fine. Maui with SKCanvasView work fine, too. We are getting in Output > Debug window the following error messages many tens of times:
Practically what happens is that that if I start the game about 4 times by pressing Play Game button on MainPage (opens GamePage that has the only SKGLView in the app) and then selecting Cancel to return to MainPage on the next screen (and repeat this 4 times), most of the SkiaSharp canvases start consistently drawing black. I tested for memory leaks using MemoryToolkit.Maui, but there seems to be none. @mattleibow Any thoughts what could be a problem here? |
If it helps anything, there are also the following error messages:
|
@mattleibow If the SKGLView implementation is the same as in Xamarin, it feels like this might be a .NET MAUI composition engine problem (possibly a threading problem / missing BeginInvokeOnMainThread), since the SKGLView is not really drawing anything meaningful when pressing Play Game, and another grid with a few SKCanvasViews appears on the top of it. It is sufficient just to make that grid appear 1-4 times (press cancel and Play Game again), and the corruption materializes. |
@mattleibow I actually now got the corruption effect without using SKGLView's, i.e., just by having SKCanvasView's in the game. However, the corruption seems to happen more often with both SKGLView and SKCanvasView present. But it looks like the culprit is SKCanvasView rather than SKGLView. Perhaps this problem is related to #2923. |
I can also confirm that the memory leak happens only when opening and closing pages, and not by showing and hiding grids via IsVisible, which makes sense, since a new page is generally created along with new controls before PushModalAsync. |
This is the iOS memory leak problem that hopefully is already fixed, pending new SkiaSharp release. I just tested this in .NET MAUI 9.0 RC2, and the problem still persists there with SkiaSharp 3.0 Preview 4.1, so a new SkiaSharp version is indeed needed. @mattleibow Do we have any indications currently what might be the timeframe for releasing the fixed version? |
@mattleibow I tried the game now on iOS with SkiaSharp 3.0 Preview 5.4, and the memory leak problem seems to persist, just as before. |
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 3.1 with .NET MAUI 9.0 Preview 6, SkiaSharp's memory gets corrupted, and it stops drawing the canvases or draws a black canvas only after showing and hiding various layouts / grids many times.
The problem seems to be with just SKCanvasViews, but the problem emerges more quickly if both SKCanvasViews and SKGLViews are present on the page.
Code
https://github.com/hyvanmielenpelit/GnollHack
Expected Behavior
Game and SKCanvasView work as in Xamarin 2.88.8 on iOS without corrupting the memory.
Actual Behavior
After opening many pages and showing and hiding layouts / grids, SkiaSharp's memory gets corrupted and it stops drawing on iOS. It is enough to press Play Game and then Cancel many times. If you do this with SKGLViews activated, 1-3 Play Game presses corrupts the memory; with only SKCanvasViews, 4-10 presses are needed. (Pressing Play Game opens a modal GamePage on the top of MainPage, and then on GamePage the MenuGrid covering the whole page on the top of main canvasView element. There are lots of SKCanvasViews everywhere.)
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.5.1
Devices
iPad 11,7
Relevant Screenshots
No response
Relevant Log Output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: