Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question WebGL game crashing on iOS device

Discussion in 'Web' started by andrej_epicoro, Mar 28, 2023.

  1. andrej_epicoro

    andrej_epicoro

    Joined:
    Feb 6, 2023
    Posts:
    1
    Hi,

    I created this thread one week ago, but it got taken down, because I posted on the wrong forum.

    I am looking for any advice or direction to solving this issue.

    I can't figure out why WebGL game keeps crashing on our iOS device. I searched trough forum and google for a solution and couldn't quite pinpoint the reason for crashing.

    Game crashes both during loading/instantiating addressables and while playing the game. Safari shortly displays "This webpage was reloaded because a problem occurred" and then the website refreshes.
    WebGL game doesn't crash on Android or newer iPhone device.

    Details:
    - iPhone 8
    - iOS 16.3.1
    - Unity 2021.3.18f1
    - WebGL 2
    - Color space - Linear

    We used memory profiler and exported results to Unity 2022 version for more data. It uses around 250MB, up to 300MB.

    upload_2023-3-28_9-34-46.png

    We also tested with Web inspector and Mac device. These are the screenshots:

    upload_2023-3-28_9-28-13.png

    upload_2023-3-28_9-28-33.png

    upload_2023-3-28_9-30-41.png


    Another issue that could be connected with my problem are pixelated shadows. This issue is also present on newer iPhones. Disabling "WebGL via Metal" solves this. Android doesn't have this problem.

    upload_2023-3-28_9-27-44.png
     
  2. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    The good news is that Apple recently fixed a Webkit bug that was causing our applications to crash and that fix landed in: 16.4 beta 3
    https://bugs.webkit.org/show_bug.cgi?id=248768
    The bad news is you'll have to update your iOS version. Sadly there's not much we can do about this from our side.
     
  3. sinedsem

    sinedsem

    Joined:
    May 7, 2020
    Posts:
    9
    Same issue on iPhone 14 Pro, iOS 17.3.1. Also crash happens when loading addressables.
     
  4. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    we're looking into this, thank you for sharing.
     
  5. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    @sinedsem would you mind sharing a build that shows the crash? we're having a hard time reproducing the problem consistently in some of our projects that use addressables.
     
  6. denkhotieu

    denkhotieu

    Joined:
    Sep 12, 2018
    Posts:
    5
    Hi, I'm experiencing the same issue on an iOS device. I'm using Unity 2022.3.19f1 and iOS 17.2.1 on an iPhone 13 and iPhone 14 Pro max.

    Here is my build: https://thientm27.github.io/Vitural-Tour-WebGL/
    GitHub repository: https://github.com/thientm27/Vitural-Tour-WebGL

    Initially, I was using only one scene. When I open it on iOS, I encounter an error after the loading screen. I tried placing an empty scene before my main scene and loading the main scene after a delay of 1 second, but the error still occurs. In some instances, iOS manages to load my main scene and operate normally, but this is not consistent.

    Android and Windows platforms, as well as an iPhone 7 Plus running iOS 15.8.2, run smoothly without any issues.
     

    Attached Files:

  7. denkhotieu

    denkhotieu

    Joined:
    Sep 12, 2018
    Posts:
    5
    Update:
    I've tried numerous methods to fix the issue, such as switching to WebGL 1, changing project settings, continuously building and testing with various fixes, but none of them worked, consuming an entire day of troubleshooting.

    However, the good news is that when I used Unity 6 beta versions to build, the product seemed to run fairly smoothly on iOS. So far, no errors have occurred, and I hope this solution can help others
     
  8. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    @denkhotieu We tested your build on iOS 17.3.1 and it never crashed :confused: We're still looking for a project that reliably crashes!
     
  9. denkhotieu

    denkhotieu

    Joined:
    Sep 12, 2018
    Posts:
    5
    This crash issue occurs when I adjust the image at 2048 level; when I adjust it to 1024, everything operates fairly well. The problem here is that the crash seems to only appear in newer versions of iOS. I'm also not sure if this is an issue with GitHub or my build version. I really hope you can take a look at it.

    I have rebuilt my product's crash and deployed it here.

    Git page: https://thientm27.github.io/Vitural-Tour-WebGL-Develop/
    Git repo: https://github.com/thientm27/Vitural-Tour-WebGL-Develop

    Here's videos of me testing the application on my iPhone 7 and iPhone 13

    IP 7: https://youtube.com/shorts/qibgsWXZkhk
    IP 13: https://youtube.com/shorts/kejzPQJyfpA
     
  10. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    @denkhotieu could you please open a bug report, so that our customer QA team can take over testing this on different devices/iOS versions and we can get a concrete repro?
     
    denkhotieu likes this.
  11. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    278
    additionally, since we haven't been able to reproduce the crash on iOS 17.4.1, can you upgrade to the latest iOS version on your iPhone 13 to see if it happens there?
     
    denkhotieu likes this.
  12. tony040209_unity

    tony040209_unity

    Joined:
    Mar 21, 2021
    Posts:
    34
    @unityruba

    Hello,
    We've recently received complaints about WebGL crashes on our end as well. The issue occurs when the game reaches a midway point, where the screen freezes. Currently, we suspect it's a problem related to how iOS handles WebGL image memory. Android users haven't reported any similar issues.

    In the game, we utilize addressable assets to load images with resolutions including 2048, 1024, 512, 256, 128, and 64. Should we suggest updating their iOS version at this point?

    Model: iPhone11,6 Unity Version: 2021.3.8f1
     
  13. iSeeGreg

    iSeeGreg

    Joined:
    Aug 17, 2020
    Posts:
    36
    Yes this seems like an issue that I'm experiencing when I attempt to load certain scenes. I get the same error. Sometimes increasing the Initial memory allocation can help in the first instance but seems like something doesn't get cleaned up from memory and it just delays the crash until the next time.

    Makes me wonder what I'm doing wrong but works fine on Android and desktop browsers. My suspicion is a memory limitation or something.
    Unity 2023.2.11f1, iOS 17.4.1, iPhone SE(3rd Gen), iPhone 12, older iPad Mini
     
  14. tony040209_unity

    tony040209_unity

    Joined:
    Mar 21, 2021
    Posts:
    34
    This issue only occurs with iOS users,
    and it is suspected to be related to the use of IndexedDB within WebGL.
     
  15. iSeeGreg

    iSeeGreg

    Joined:
    Aug 17, 2020
    Posts:
    36
    Sounds plausible. Are you aware of any workarounds?
     
  16. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    Maybe because 2021 is ancient
    "Unity 2021.3 is now the legacy LTS. It will be updated monthly until it reaches the end of its support cycle in mid-2024."
    https://unity.com/releases/editor/qa/lts-releases

    Why are you still using 2021 for web???
     
  17. dippyshere

    dippyshere

    Joined:
    Oct 11, 2020
    Posts:
    1
    For what it's worth, I've tried projects built in Unity 2021.3.24f1, 2022.3.7f1, 2022.3.16f1, 6000.0.0b13 & 6000.0.0b15 on both iOS 17.3-17.5b4 (iPhone 13 Pro) & Android 12-14 (Nokia 6.1); and none have worked reliably on iOS. No matter the build configuration, or utilisation of addressables, I've found that projects will work up until they use a certain amount of memory (whether this is while the wasm & initial data is still loading, or during runtime). In my most recent project on 2022.3.16f1, we utilise addressables to keep our initial download times low. This project will load to our bootstrapping scene just fine, but exhibit this crashing behaviour while it is downloading additional scenes and resources.

    If the issue is with the use of IndexedDB, is it possible to enable/disable the use of IndexedDB depending on the browser the build is running on?
     
  18. AdamandEveStudios

    AdamandEveStudios

    Joined:
    Apr 19, 2022
    Posts:
    60
    This depends on a variety of factors and can be solved quite easily:
    • What error message does browser give upon crash
    • What is the console printing before / right before crash
    • What's your final build size
    • How big are your addressables
    • Whats your max texture size
    • What texture compression format are you using
    Addressables are good to keep initial download size down, but if they are absorbing all your very limited memory your going to have crashes.

    https://blog.unity.com/engine-platform/web-runtime-updates-enhance-browser-experience
    "In Unity 6, you will be able to enable 4GB memory support. This enables bigger real-time 3D experiences on the web, making use of the larger memory available to desktop browsers. In the future"

    Might want to switch over workflow to prepare for Unity 6. 4GB for web games is everyone's dream come true
     
  19. iSeeGreg

    iSeeGreg

    Joined:
    Aug 17, 2020
    Posts:
    36
    Well I was able to reduce the occurrence of this issue for me by really cutting back on the texture memory burden in the asset bundle I was loading, and increasing the starting heap size to 512MB. Not gone completely but the theory about heap resizing kind of has a bid more cred IMO
     
  20. alvinw

    alvinw

    Joined:
    May 20, 2016
    Posts:
    4
    I thought Unity 6 finally officially supports mobile WebGL. But I'm still crashing on iOS Safari due to memory. We've reduced our app to use very little textures and it still is very unstable.
    Device logs show highwater killing it due to memory pressure. Doesn't happen all the time, but I can get it to happen regularly enough. Only iOS safari!

    50733.283 memorystatus: killing_highwater_process pid 7700 [com.apple.WebKit.WebContent] (highwater 100) 1807222KB - memorystatus_available_pages: 148247 compressor_size:167001
     
  21. iSeeGreg

    iSeeGreg

    Joined:
    Aug 17, 2020
    Posts:
    36
    Another thing to consider that I've just discovered while trying to work around this issue, is that mobile builds use a different texture compression method so if the build is made with DXT compression they will be loaded uncompressed.

    In the case of a full sized iPad, by default the browser is told to use the desktop site also. It does this by changing the user agent to impersonate a Mac. So no matter what it will load the app that's built with DXT (I think it's more unstable in this state), unless I turn off the Desktop Website setting in Safari. Then the user agent reflects iPadOS.

    iPad Mini and iPhone use the correct user agent by default as far as I know