Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Is it possible to catch out of memory errors on WebGL

Discussion in 'WebGL' started by liortal, Aug 26, 2019.

  1. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,532
    When the game runs out of memory and crashes with the native dialog, is there any option to get a callback or react to this, and report this so we know our game crashed?

    Is there any guide or manual on how to do this ?
     
  2. svg_mBerger

    svg_mBerger

    Joined:
    Nov 5, 2018
    Posts:
    7
    I would also like to know this
     
  3. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    You can override the UnityLoader Error callback - it doesn't look like it has actual different event types and currently I'm doing a string comparison which isn't ideal, but it does work.

    Code (JavaScript):
    1. UnityLoader.Error.handler = function(e, t)
    2. {      
    3.     if (e.message.indexOf("out of memory") != -1 || e.message.indexOf("Array buffer allocation") != -1)
    4.     {
    5.         // Handle 'out of memory' errors.      
    6.     }
    7.  
    8.     // Handle other errors.
    9. };
     
    liortal likes this.
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,532
    Great. What other errors does it report?
     
  5. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    214
    Basically anything that normally comes up as a JavaScript alert popup, excluding the mobile compatibility check which has its own function briefly mentioned here. There's a few more obscure ones which you'd have to do some more work with to catch (e.g. WebGL rendering errors, warnings, Emscripten messages, etc.) although since these are reported to the console I haven't pursued it further myself.