Search Unity

iOS 15 + WebGL 2 issue

Discussion in 'Web' started by LW2021, Sep 29, 2021.

  1. LW2021

    LW2021

    Joined:
    Aug 16, 2021
    Posts:
    4
    Hi,

    I have a very weird problem, and I'm not really sure where to start searching for a solution. The problem is with the latest iOS update (15) and WebGL 2, as the title suggests.

    The iOS 15 update automatically enabled WebGL 2 for its users, which should be a good thing. However, whenever I try to load any of the scenes with the racing tracks on them, the game kind of freezes. At this point the game gives me an empty screen (black) and nothing really happens. No log output, nothing. After a few minutes though, I get death messages in the browser console. Normally this would happen in a few seconds instead of minutes without controlling the car. Also note that, scenes with barely anything in them, such as only UI stuff, do seem to work.

    The weird part is that when disabling WebGL 2 from the Safari settings, or forcing a WebGL 1 build-only via Unity, the game runs okay. Also, on iOS 14 with WebGL 2 enabled in browser settings it seems to work fine.

    This is really all I managed to find out after trying random things for a few hours. Does someone know what could be causing this? Or how I can get some more useful information regarding what's going on? I'll try some extra things and share anything I find here.

    Thanks in advance! :)
     
  2. Affentot

    Affentot

    Joined:
    Nov 3, 2016
    Posts:
    1
    Hi,
    i had the same problem. After a lot of research i found one little thing that helps. I disabled the "Lightmap Streaming" in the Player Settings and now everything works fine. Maybe this little trick helps you.
    Good luck!
     
    DBarlok likes this.
  3. chilledbits

    chilledbits

    Joined:
    Jan 4, 2018
    Posts:
    17
    Same problem here.
    My game crashes "randomly" in iOS (15.0.2) Safari. On Chrome Browser (iOS) it seems to be still working.
    "Lightmap Streaming" was already disabled here without any effect :/
     
  4. chilledbits

    chilledbits

    Joined:
    Jan 4, 2018
    Posts:
    17
    Update:
    The problem seems to be the "new" Webgl2.0 support of iOS Safari.
    You can disable it directly on the phone:
    Settings >> Safari >> Advanced >> Experimental >> WebGl 2.0

    Or set webgl1.0 in the build-settings of Unity until this issue gets fixed.

    I can reproduce it now this way. Not a solution but at least a temporary workaround.
     
    unity_gh and james_unity467 like this.
  5. LW2021

    LW2021

    Joined:
    Aug 16, 2021
    Posts:
    4
    Thanks for your answer @Affentot. Sadly your solution didn't work for me. I ended up doing the same as @chilledbits mentioned; creating a WebGL 1.0 only build for Apple devices. This works fine for now, but hopefully this will be properly fixed in the future.
     
  6. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    There is a bug in Safari WebGL2 that has been fixed in the current iOS 15.2 beta, which is probably this same issue.
     
    chilledbits, xiangshushu and Siba_M_M like this.
  7. Siba_M_M

    Siba_M_M

    Joined:
    Aug 11, 2020
    Posts:
    15
    I'm facing the same issue.. Suddenly the WebGL application that was working fine is crashing and reloading on iOS devices
    Is there a way to force iPhones/iPads to use the WebGL 1.0 ?
    (My app has Auto Graphics API checked )
     
  8. JG_GC

    JG_GC

    Joined:
    May 11, 2018
    Posts:
    1
    I'm also experiencing this problem, my app crashes when I tap on a button, all this button does is turn a gameobject on or off, I'm also wondering if we can force iPhones/ iPads to run WebGL 1.0 as I don't want to lose my post processing effects on android by just building for WebGL 1.0, I know how to check if the device is an iphone/ ipad from the index file but I'm unsure how to force Unity to run a specific version of WebGL on start
     
  9. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    Can you submit bug reports for these iOS issues? It is important to get iOS WebGL2 working well.
     
  10. Nerzal

    Nerzal

    Joined:
    Aug 5, 2015
    Posts:
    5
    On iOS 15.1 my webGL builds won't even load and start with a TypeError: load failed.

    All in all, it does not feel like apple products are supporting webGL well in any form.
    Low poly games, that run on mid/low end windows/linux machines with maximum FPS tend to lag on macs.

    Is there anything that unity provides to run tests with webGL on iOS devices?
    I have none, so i cannot even debug these problems.
     
  11. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    Unity has been testing iOS15, but there's only so much we can test as the web is a big platform. Apple recently turned on the Metal back-end for WebGL2, and was the source of a couple regressions, but they're working hard with Google to get them sorted out. As Unity is deprecating WebGL1 (it is very old and not very capable ), finding and fixing issues with WebKit's WebGL2 is very important. Submitting issues, especially with small reproducible examples, is the best way to get the problem pushed up the priority list.

    I know some of these issues have been fixed in iOS 15.2.
     
    Nerzal and xiangshushu like this.
  12. mesmes123

    mesmes123

    Joined:
    Oct 11, 2021
    Posts:
    9
    I have the same problem as mentioned above.
    When I tried all the suggestions above (Disable the "new" WebGL 2 / Lightmap Streaming - OFF) the only way to get it working on IOS (version 15.01) was to build my project to WebGL 1...
    Hope it will be fixed soon.

    After I updated my IOS to version 15.02 beta the Unity build WebGL 2.0 finally works!
     
    Last edited: Dec 13, 2021
  13. chilledbits

    chilledbits

    Joined:
    Jan 4, 2018
    Posts:
    17
    I can confirm that with iOS 15.2 (not 15.02) this seems to be not an issue anymore.
     
  14. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    Thanks for the confirmation.
     
  15. davidg_

    davidg_

    Joined:
    Feb 21, 2022
    Posts:
    4
    Hi! I have a similar problem when running on iOS 15.4 beta (everything works fine on 15.3). I've tried all the suggestions posted here before, but with no success. I'm using Unity Editor 2021.2.10f1.
    As soon as I add a button to my scene, which prompts me to install the TextMeshPro essentials package, I'm no longer able to load my game (even on very high-end devices).
    I've attached the logs from one of the devices.
    Is there a fix for this? Please let me know if you'd like me to provide any more info.

    Thank you!
    - David
     

    Attached Files:

    • logs.txt
      File size:
      24.3 KB
      Views:
      321
  16. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
  17. petja32

    petja32

    Joined:
    Jan 24, 2022
    Posts:
    4
    Hey, I'm using unity 2022.1.0b9 and am having similar issues on IOS 15, after finishing loading it immediately gives an error Out of bounds memory access. I tried with empty scenes and changing compression values but nothing fixes this issue.
     
  18. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
  19. petja32

    petja32

    Joined:
    Jan 24, 2022
    Posts:
    4
    Yes 15.4!
     
  20. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    We're working with Apple to get it fixed. I've been pushing on Apple the urgency of it as much as possible.
     
    petja32 likes this.
  21. MyopicSquid

    MyopicSquid

    Joined:
    Nov 28, 2017
    Posts:
    2
    This would be great thanks, On 15.4, disabling WebGL 2.0 and WebGL on Metal in Safari experiemental settings does not resolve the Out of Bounds error on loading.
     
  22. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    The issue has to do with WASM and not WebGL. This failure is something we're very concerned about, and I wish there was more we can do other than pushing on Apple and hoping they fix it soon.
     
  23. justiino

    justiino

    Joined:
    Feb 17, 2022
    Posts:
    1
    Thank you for keeping us updated!

    I’m curious if we’ll need to wait for a new release of iOS until this is resolved.

    Is there perhaps a workaround we can implement in the meantime?
     
  24. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    I have not been able to find a work-around. The problem seems to be from the WASM size being bigger than 9MB. If you make an empty project, it works, but as soon as the WASM gets bigger than about 9MB, it crashes.

    The WebKit bugzilla report is here, https://bugs.webkit.org/show_bug.cgi?id=237180. We've had Google and people at Apple check in on it, but in typical Apple fashion there's no feedback.
     
  25. M-SugayaTakuma

    M-SugayaTakuma

    Joined:
    Apr 9, 2020
    Posts:
    12
    We tested with Unity2021.2.15f1 and Unity2022.1.0b11.

    Projects with only simple components such as Main Camera, Directional Light, and Cube loaded successfully, but when we added Image or PlayableDirector components, the loading stopped halfway through.
    (Runtime Error: Out of bonunds memory access)

    We also found that the problematic components generate errors when the object is called.
    In other words, the problem is not caused by being included in the project, but by being used.

    Also, the size of WASM in that case did not exceed 9MB either, but was about 5.3MB, and the total size of the build was about 6.8MB.

    These behaviors seem very strange and do not seem to be an Apple-only problem.
     
  26. sercand

    sercand

    Joined:
    Nov 7, 2013
    Posts:
    8
    I have tested with several unity versions and build sizes. It doesn't affect by the binary size. I can make it run with build sizes over 15 MB as well. How did I make it run is a different story: I added a
    Code (JavaScript):
    1. debugger;
    to somewhere in js code. If I wait enough and press continue on my js web console it started working correctly without any wasm issue. WebGL 2 issues still remain so I was forced to work it with WebGL 1.
     
  27. simon_zappar

    simon_zappar

    Joined:
    Mar 23, 2018
    Posts:
    16
    That's an interesting finding @sercand - sounds like it might be something to do with the wasm tiering-up to a higher JIT whilst executing that causes the problem. I'm still digging for workarounds (and also pushing Apple on the bug report Brendan linked) as this is a pretty major issue for us.
     
  28. simon_zappar

    simon_zappar

    Joined:
    Mar 23, 2018
    Posts:
    16
    @brendanduncan_u3d - Any chance you could try a -s WASM=0 build? Would probably be big and slow, but might actually be functional. I'm trying to dive in and debug what's going on with your examples from the webkit bug but don't know the Unity webgl build system, and don't have Unity installed here at the moment
     
  29. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    @simon_zapper ASMJS is deprecated by browsers, so it wouldn't be a viable solution, and I'm not sure it would provide useful info for debugging. I am currently dedicating my time to finding an answer to this since Apple hasn't been helpful thus far.

    The problem is coming from some data is being evaluated differently on iOS15.4 than in other environments. From my latest investigations, an IL2CPP class type ID is saying it's 0, where it's never 0 on any other browser. That 0 causes the IL2CPP class object to return as null, and I suspect some following code is updating the class data, not null checking, and writing to the null ptr. Emscripten has a memory heap validation check that it does to see if something wrote to the null address. On older Emscriptens, pre Unity 2021.2, it printed this as a warning to the console. On newer versions of Emscripten, it calls abort.

    For experimental purposes only (not proposing this as a solution!) if you edit the project build's framework.js file, find the code
    abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
    and replace it with
    console.warning('Runtime error: The application has corrupted its heap memory area (address zero)!');
    Then a theory is that it would continue running, and that "corruption", despite not being good, wasn't in fact critical.

    But I will continue narrowing it down to exactly where this problem is coming from, and find an exact point of failure that either we can patch on our end or get Apple to fix, since they don't seem to want to fix anything that they have to spend any time investigating themselves.
     
  30. simon_zappar

    simon_zappar

    Joined:
    Mar 23, 2018
    Posts:
    16
    Thanks for the update Brendan.

    I had noticed the stack cookie check code was where things were failing on your minimal clear-color example, but I believe other projects show other errors. Looks most likely just a Safari VM bug that corrupts random stuff when running perfectly valid code, but obviously if you are able to narrow it down to a trigger in the Unity code that can be fixed that would be brilliant.

    Is it possible for users to customise the emscripten command lines for the webgl build? There's various flags and options that I'd be happy to play around with if so. I added an issue on emscripten GitHub just mainly to get their advice too - that's here: https://github.com/emscripten-core/emscripten/issues/16526

    I'm also dedicated to this at the moment, looking for workarounds. My current plan:
    1 - Try a wasm2js converted build (which I expect to be functional but perhaps too slow to be useful)
    2 - Look at wasm-split to see if we can separate the wasm into smaller modules and if that avoids the bug
    3 - Try to bisect in the open-source webkit code to identify the breaking commit (if it is in fact broken there) to give better hints to Apple engineers

    We're also leveraging any contacts we can find to bring more pressure on Apple in the hope for a fix and a point release ASAP.
     
    Last edited: Mar 18, 2022
  31. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    I suspected the Cookie abort might not have covered everything, and the corruption that triggered that might be more wide spread. Just looking for anything that might help in the meantime.

    I'm not sure you'd find the problem in open-source webkit, since they use a separate branch for iOS, and it doesn't happen on desktop WebKit/Safari.

    We've also been pushing on contacts at Apple...but it's Apple.

    You can set Emscripten linker args in ProjectSettings/ProjectSettings.asset, emscriptenArgs value.

    You might also be able to set Emscripten compiler flags, at least for the code generated by IL2CPP, by setting the EMCC_CFLAGS environment variable.
     
  32. simon_zappar

    simon_zappar

    Joined:
    Mar 23, 2018
    Posts:
    16
    Thanks for the hints. Assigned myself a seat and downloading the editor now. Looks like the -s MAYBE_WASM2JS only introduces minimal runtime changes, so I'm still trying to patch your built examples first.

    Haven't tried to repro with open-source WebKit yet as finding a workaround is priority #1. Apple in general are very opaque on this stuff, but at least some in the Safari team work slightly more collaboratively on the webkit bug tracker. Not the case yet on this bug, but I live in hope - we did get a few other critical things fixed during the iOS 15.4 beta phase, but unfortunately this one wasn't on our radar until Wednesday :(
     
  33. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    I am seeing some promising results from updates to IL2CPP I just pulled into my build of Unity, the minimal tests that were crashing, are no longer crashing or having the errors I was seeing before. I'm doing a build of a bigger project now. I'm pessimistically hopeful.
     
  34. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    Not quite. The new IL2CPP fixed the issues with that minimal test, but larger projects still have errors. I'm still hopeful we can find a way around the issue.
     
  35. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    Update: I may have found a solution to the problem, or at least a specific compiled file that causes the crash, which I can swap out with a working one to get a crashing build working. If it works out, this would be something we can fix on the Unity side and wouldn't require waiting on Apple to fix whatever they did to break things.

    The other bad news for iOS 15.4 is that WebKit introduced a number of very bad regressions in the WebGL graphics side of things, and even without the WASM crash, rendering will still be bad for most things. The graphics problems will be easier to work with Apple/Google to fix.
     
  36. fufuninja

    fufuninja

    Joined:
    Aug 8, 2021
    Posts:
    2
    Thanks for the hard work Brendan! If I may ask, how will the fix be rolled out/shared with? I am too facing this issue where my users who are playing our browser based Unity WebGL games and upgraded to the recent iOS 15.4 build could not have their games loaded and getting stuck at 90%
     
  37. simon_zappar

    simon_zappar

    Joined:
    Mar 23, 2018
    Posts:
    16
    Great updates Brendan, thanks for your great work on this so far. On the graphics regressions, is webgl1 still working well enough? We noticed some broken three.js webgl2 content seemingly triggered by the use of SRGB8_ALPHA8 textures in the beta. Haven't yet noticed any regressions with our webgl1 content at least.

    I've managed to get a wasm2js build of your minimal clear-color developer build working on iOS 15.4 too, and in a way where it's opt in via a ?_wasm2js=1 query string for testing. Looking into applying the same thing to a more complex example project now.
     
  38. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    I haven't investigated webgl1 on the new iOS yet, it might work since I don't think WebGL1 uses the Metal back-end.

    I found a specific line line in a file from IL2CPP that triggers the WASM crash on iOS. In a specific circumstance, memcpy is failing. But I have a "fix" that seems to resolve the issue, even if I don't fully understand why it fixes it. I also still don't understand why this particular circumstance causes memcpy to fail on just iOS 15.4's WASM VM. I'll discuss with management about how we'll roll out the fix, assuming others can replicate my success. The worse case, there is a simple way to do the fix yourself without waiting for a Unity release, but I need to do more testing before I can recommend it.
     
    Last edited: Mar 21, 2022
    xiangshushu, petja32 and nfynt-zap like this.
  39. petja32

    petja32

    Joined:
    Jan 24, 2022
    Posts:
    4
    Could you post the workaround, so we can get our Games to work temporarily?

    Oh and thank you for all your hard work!
     
  40. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    Since it can't get any worse than it already is:

    In your Unity installation (on MacOS, in Unity.app/Contents), edit:
    il2cpp/libil2cpp/metadata/GenericMetadata.cpp

    Find the line:
    const Il2CppType* GenericMetadata::InflateIfNeeded

    Add:
    #pragma clang optimize off
    to the line before that function to turn off compiler optimizations for the function, and add
    #pragma clang optimize on
    after the end of that function to turn compiler optimizations back on again. This will disable compiler optimizations for that one function. In my tests, this has been enough to stop the crash.

    In your Unity project, delete the directory Library/Bee/artifacts/WebGL/il2cpp to be sure it picks up the changes to that file. Also make sure your iOS Safari isn't trying to load a cached version by going to Settings / Safari and selecting Clear History and Website Data. I've spent plenty of time chasing ghosts by not clearing a cache.

    Memory errors are notoriously hard to track down, especially when only one platform, and one version of that platform, has the memory corruption, and that platform is iOS.
     
  41. NotEaZy

    NotEaZy

    Joined:
    Dec 8, 2018
    Posts:
    3
    Thanks Brendan but i can't find the Library/Bee/artifacts/WebGL/il2cpp in my project directory

    Edit: My game now can launch and won't stuck in 99% but after playing for a while the game UI started to flicker which doesn't happen before.
     
    Last edited: Mar 22, 2022
    chilledbits likes this.
  42. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    The Library directory should be generated after you do a build. I meant if you edit the GenericMetadata.cpp file, and if you already have a build for your project, you should delete that Library directory to make sure the next build gets the change to GenericMetadata.cpp. You wouldn't need to delete it if you hadn't built the project yet, or if you had already deleted it after making the change.
     
  43. Phobetor

    Phobetor

    Joined:
    Jan 12, 2017
    Posts:
    3
    Dunno if it works 100%, but your solution @brendanduncan_u3d worked for me, many thanks!
     
  44. nfynt-zap

    nfynt-zap

    Joined:
    Jun 3, 2021
    Posts:
    20
    Awesome fix @brendanduncan_u3d.
    This seems to work for me as well, building on windows for WebGL. I was skeptical if clang macro would work on windows but Unity seems to be taking it well.
     
  45. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    @nfynt-zap Emscripten, which compiles C++ to WASM, is a clang compiler.
     
    nfynt-zap and OceanX000 like this.
  46. george_playbite

    george_playbite

    Joined:
    Sep 27, 2018
    Posts:
    38
    @brendanduncan_u3d Thanks for that workaround! We have many games which we have building through Unity Cloud Build and automatically deploy successful builds. It'd take a lot of time for us to start doing that manually. Any chance you guys could update Unity Cloud Build with this workaround temporarily?
     
  47. bogdan-serbanescu

    bogdan-serbanescu

    Joined:
    Jun 14, 2017
    Posts:
    20
    Thank you for this! The workaround seems to work with no noticeable bugs. Do you reckon there will be any performance impact caused by this?
     
  48. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    @bogdan-serbanescu There should be no performance impact. I got the disabling of the compiler optimizations limited to that one function, which shouldn't have any noticeable impact.

    @george_playbite I don't think that will be possible, but I'll bring it up.

    I have gotten word Apple is working on this as a P1 Major issue. But of course since WebKit is tied into the OS, even when they have a fix, it still will have to find its way into their iOS release schedule.
     
  49. M-SugayaTakuma

    M-SugayaTakuma

    Joined:
    Apr 9, 2020
    Posts:
    12
    We too tried the workaround and were able to activate it successfully. Thank you very much. We appreciate your efforts.

    In Unity 2020.3.30 with the improvements added, the build failed if Enable Exceptions in Publish Settings is set to None.
    When I changed it back to Explicitly Throw Exceptions Only, the build succeeded.
    This did not seem to happen with Unity2021.2.15.

    I found during testing that only iOS15.4 does not seem to refresh the Canvas UI properly.
    It still seems that there are still many bugs in the WebGL functionality itself in iOS15.4 since it occurs only in iOS15.4.
     
  50. brendanduncan_u3d

    brendanduncan_u3d

    Unity Technologies

    Joined:
    Jul 30, 2019
    Posts:
    437
    @M-SugayaTakuma There are a lot of regressions for WebGL2 with iOS15.4. Most are in the process of being resolved by Google/Apple. Are you using WebGL2, or WebGL1?