Search Unity

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,259
    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:
    206
    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,259
    Great. What other errors does it report?
     
  5. JJJohan

    JJJohan

    Joined:
    Mar 18, 2016
    Posts:
    206
    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.