Running out of VRAM on iOS

I may be having this same issue - is there any way to know how much VRAM is available on a device?

I have a single view IOS app with a webview containing my game that crashes. IOS Safari also is crashing.

I compressed some of the 2048 x 2048 images using the default settings and the affects on the VRAM were negligible

thanks,
Mitch

Nope, which sucks completely.

Surprised it makes no difference, you should see a significant reduction in VRAM usage :thinking:. Is there a build/published URL you can share?

You are shared on the project from a prior interaction! the branch is master2
https://playcanvas.com/editor/scene/1300676

Is it my understanding that textures that are not power of 2 size cannot be compressed at all?

Would love any tips you have, can also do a build with and without compression if that is helpful

That is correct.

Have you looked at the profiler and checked VRAM usage? What’s the most you are using without Basis? A quick playthrough shows 55MB total which shouldn’t crash iOS (Master branch)

Master branch is old dont use that - its master2 is the main one now. I got 78 MB max by playing a bunch of games. on IOS i can crash it if i pull it up and as quickly as i can login

do you think it could make a significant difference modifying all my images to be power of 2?

Like is a 100x150 image more efficient compressed by scaling up to 256x256 and compressing it rather than leaving 100x150 alone?

A couple of things to note here:

  1. You have both the Texture and Texture Atlas for a Sprite. You only need the the Texture Atlas for the Sprite so the Texture asset can be deleted. So right now, you are downloading and using VRAM for an unneeded duplicate.

  2. You have one Texture Atlas per Sprite. While you can do this, it is recommended to pack Sprites into a single atlas. This gives a couple of advantages, much fewer network requests so potentially quicker download times and you can have the Texture Atlas as a power of 2 to compress. See Using Texture Packers | Learn PlayCanvas

  3. I took a 346 x 101 texture. Uncompressed, it uses 140KB VRAM. When made into a 512 x 128 and used Basis, it uses 87.4KB VRAM

  1. Awesome, so for the texture can i just toggle off “preload” so it never loads (if its never needed like you said)

  2. Cool so should i probably do 1 texture atlas per “scene”? Assuming all the sprites are common. What about if i have a character sprite that occurs in multiple scenes, should i just do 1 texture for that character alone, or should i pack him into each scenes texture atlas?

  3. Good to know, so its good to go bigger so i can compress.

  4. Follow up: how can i clear up VRAM, I noticed it increased the first time a sprite turned on (i have a solar flare that pops up every min in a game and the texture is huge), but then when it was gone the vram didn’t go down. Would i have to delete the entity for that to go down?

  5. Would you reccomend anything besides this plan for lowering VRAM?

Thanks a million,
Mitch

  1. Yes.

  2. Depends on what you do for loading/unloading but one per scene sounds sensible. Maybe a common texture atlas too.

  3. You need to unload assets (textures) to free up VRAM

  4. Smaller in dimensions textures, less textures, load only what you need and unload what you don’t. There’s not really much else unfortunately.

78MB VRAM shouldn’t crash iOS either :thinking: As this is in a WebView, maybe there’s something in the application code of the native app that can allow you to have more memory?

Okay cool so for #4 what does that mean if im using an entity with a sprite renderer. Would deleting the entity or sprite component unload that (or the sprite from the sprite component), or do i have to in code manually unload it?

And yeah i have not seen it get past 80MB, In the most complex scene draw calls are about 105 per frame, could that be related?

And yes its a single view ios app with a WebView. I can look into that as well

you can experience it yourself by logging in really quuick in safari mobile and clicking “Capture The Flag”

I profiled it in xcode, which can get RAM usage but not VRAM and it seems to be peaking like 19MB for the whole application, and CPU peaking at 18% (avg 5%)

No, you will also need to access the Sprite and Texture Atlas assets and unload them via Asset | PlayCanvas API Reference

A small example can be found here for scene loading but same process: Loading Scenes | Learn PlayCanvas

Draw calls shouldn’t matter.

I don’t understand why loading really quick would crash it? Maybe you have a different issue that is dependent on timings/race conditions? Do you have an errors or logs in the devtools console when that happens?

Okay, yeah if you are not concerned with VRAM or draw calls maybe its not performance but something else. We have Raygun configured for Playcanvas, so all in game issues are reported, but not xcode errors for our app (i dont think a browser crash is a webview error, there are no logs in xcode for that event)

Are there any events you are aware of in playcanvas that would cause the browser to crash and restart? We are not getting reports from schools (our users) that desktops are doing this, only ios

I’ve never seen PlayCanva outright crash unless the tab runs out of memory. If the tab is crashing, than Raygun won’t help as it’s part of the browser tab :sweat_smile:

One random thing to try is to disable device pixel ratio to see if that makes any difference.

Also, just to verify, what do you mean by ‘crashing’?

Okay i will try that and report back - Crashing meaning the webview crashes and reloads the page in ios

Yeah, that sounds like a memory crash in the tab

I did test out a tab and the chrome task manager says “1.8GB” memory footprint, so i think its more likely that then a bug. Im going to compress all my audio and images i think.

Did track down the actual crash log in ios but having issues debugging it

023-03-21 11:03:06.276531-0400 BlueStreak Math Relaunch[7423:527865] [Process] 0x1120009d0 - [PID=7427] WebProcessProxy::didClose: (web process 0 crash)
2023-03-21 11:03:06.277779-0400 BlueStreak Math Relaunch[7423:527865] [Process] 0x1120009d0 - [PID=7427] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=Crash
2023-03-21 11:03:06.279488-0400 BlueStreak Math Relaunch[7423:527865] [ProcessSuspension] 0x11101c1e0 - ProcessAssertion: Failed to acquire RBS Background assertion 'ConnectionTerminationWatchdog' for process because PID 0 is invalid
2023-03-21 11:03:06.281588-0400 BlueStreak Math Relaunch[7423:528005] [ProcessSuspension] 0x11101c1e0 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=0, error: (null)
2023-03-21 11:03:06.283667-0400 BlueStreak Math Relaunch[7423:527865] [Process] 0x104026418 - [pageProxyID=6, webPageID=7, PID=7427] WebPageProxy::processDidTerminate: (pid 7427), reason=Crash
2023-03-21 11:03:06.291722-0400 BlueStreak Math Relaunch[7423:528005] [assertion] Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
2023-03-21 11:03:06.291853-0400 BlueStreak Math Relaunch[7423:528005] [ProcessSuspension] 0x11101c240 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebProcess Background Assertion' for process with PID=7427, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
2023-03-21 11:03:06.317065-0400 BlueStreak Math Relaunch[7423:527865] [Loading] 0x104026418 - [pageProxyID=6, webPageID=7, PID=7427] WebPageProxy::dispatchProcessDidTerminate: reason=Crash
2023-03-21 11:03:06.364931-0400 BlueStreak Math Relaunch[7423:527865] [Process] 0x1110647a0 - GPUProcessProxy::gpuProcessExited: reason=IdleExit
2023-03-21 11:03:06.365208-0400 BlueStreak Math Relaunch[7423:527865] [Process] 0x112001300 - [PID=0] WebProcessProxy::gpuProcessExited: reason=IdleExit

Let me know if you can make any sense of this

Up to the login screen (I can’t sign in any more), it’s using 50MB of system memory

Does a published build of this crash on a cold start or is it over several sessions of the game, going between your native app and the webview game?

This is currently at the stage where I start ripping out features like all audio and seeing what happens

Cold start crashes it,
What is too many MB for RAM in your opinion?

I guess i will compress the Audio and Images and see what happens

100MB-150MB of VRAM. I’ve not yet heard of a case of running out of Application memory being a consistent cause yet.

1 Like