We are building an application, which consists from 2 Unity applications on the same page. One of them is stationary, the second one can be loaded at any point.
Both apps are included in almost empty root HTML page using 2 iframes.
When running on any PC browser or Android browser, we have no issues. But on iOS (any browser), after loading the first Unity instance, the loading of the second crashes the page. Crash occurs after the second instance successful loaded. The second instance has only empty scene with 0 logic. We are using the URP and latest Unity 6.
We tried countless options: changing almost any option, building empty projects, etc. But we’re always getting a crashed page. If we are keeping to reload iframe, on some 10th run it can stay without crash.
Unfortunately, no errors or any helpful logs. The only corellation we found, that the first instance will also crash if this code isn’t added:
How much memory is your Unity build using approximately? There is a bug in iOS Safari that will crash the web page when to much memory is allocated. Other browsers will give you a graceful error that no more memory can be allocated.
My hunch would be that you are running out of memory with the second instance inside the same browser tab.
Was going to say the same about memory. Specifically since iOS is extremely limiting in that regard. 500 MB memory usage of a single tab may have it force reloaded (on certain devices).
Staying within this low limit may be pushing it too far with two Unity instances. Although last time I checked you can start an empty project with well below 100 MB. So it really depends on the kind of content you are planning. You’d also have to treat iOS as your primary development and testing platform (various devices, not just simulator) to avoid any surprises.
If possible, change the “two applications” requirement. You could move the content of the second instance inside the main Unity application for example.
The both builds are almost empty Unity projects with blank scene to find a crash solution, with stripping enabled. So the memory shouldn’t be a limitation.
Also the page crashes only when a second iframe with unity app is loaded. I’m sure you can reproduce this by building 2 separate empty projects in some folder with minimum webgl template, import them in the root folder as iframes and rum python local server.
Unfortunately, we are launching some sort of “mini games” from the main “home app”. Those “mini games” should be separate projects due to their amount and release simplicity.
Could you enable the “Diagnostics Overlay” for your builds and test them separatly?
From the way the page crashes it seems most likely to me that it is the memory bug of iOS Safari.
If the WASM heap needs to grow slowly, it is possible to trigger this bug very early.
As a workaround I can recommend to use the diagnostics overlay to to figure out the memory consumption of the Unity Web build and set the initial heap in the player settings to that value + some small margin. You can also do this testing in a desktop browser and use those results.
From my experience the bug triggers earlier if you start of with a small heap and slowly grow it vs. setting the right size from the start. With the former it sometimes crashed with just under 500 MB on older iPhones and with the later I was able to get out about 700 MB sometimes even more.
After debugging and playing with different settings, I manage to run two instances in 2 iframes, but very unstable.
But after making single HTML page with two canvases and loading 2 instances without iframes, crashes gone.
So I almost sure, even the problem can be related to the bug above, we have something more in play with iframes. Does Unity have any desire to take a look on 2 iframes case? Should I make a bug report?
Hmm, thats very interesting. It would be nice if you can create a bug report. I wonder if it is something about the size of the canvases and resizing the matching render targets going wrong because of the iframe setup.
The memory consumption definitly seems reasonable to run two instances inside iOS Safari(even with the bug). So this could be something else worth investigating.
The resizing can be the case. Because I find some correlation. If the meta name="viewport" ... isn’t used, even 1 iframe can crash, when I add the tag accordingly to Unity template - it’s gone.
Currently, only one question left - how to unload the second instance correctly. Even with .Quit and removing the canvas, loading the second time the second instance can cause the crash. Also I see that heap isn’t downcaling, only used part.