Search Unity

Solution for TypeError: null is not an object (evaluating 'xhr.response.byteLength')

Discussion in 'Web' started by doterax, Sep 23, 2019.

  1. doterax

    doterax

    Joined:
    Jun 10, 2015
    Posts:
    4
    After we upgrade our Unity from 2017 to 2019.1.10f1 and 2019.1.14f1.

    We have started to receive strange reports from our players about error alert in WebGL version of our game. Some players sent several screenshots with alert.

    Text on alert:

    An error occurred running the Unity content on this page.
    See your browser JavaScript console for more info.
    The error was:
    TypeError: null is not an object (evaluating 'xhr.response.byteLength')


    That was elusive bug. We try to figure out whats going wrong, but our team failed to reproduce this issue.
    We instruct our support guy to deeply communicate with players that faced this issue and one time he succeeded with bunch of screenshots of game and browser console.

    We found bug in Unitys WebGL XHR Caching system CachedXMLHttpRequest.js and found disappointing thing that bug in phase when data already put in cache. And system start build string to console.log about success download.

    If you faced with this type of issues just substitute file:

    {UnityRoot}\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\prejs\CachedXMLHttpRequest.js


    with attached one.

    And let me know about further behavior of your app. Issue is gone?

    PS. For Unity3d WebGL Team, you can freely use this fix in folowing patches :)
     

    Attached Files:

  2. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Thanks for this info!

    I am not actually sure I follow how at first xhr.response.byteLength would be valid, but then after the put call, xhr.response could be getting invalidated? There does not seem to be anything that would touch xhr.response in that way, that would catch my eye.

    Are you sure that the change resolved the original problem?

    If not, could the root issue rather be that the HTTP request comes back as HTTP 200, but the response was empty, leading xhr.response to be null/undefined in the first place?

    If so, I would suggest that instead of

    var xhrResponseByteLength = xhr.response.byteLength;

    would instead have

    var xhrResponseByteLength = (xhr.response && xhr.response.byteLength) | 0;

    to ensure that the response is there.
     
  3. doterax

    doterax

    Joined:
    Jun 10, 2015
    Posts:
    4
    Yes, after I made this fix problem was gone.
     
  4. Samasab

    Samasab

    Joined:
    May 13, 2018
    Posts:
    13
    Solved my issue. I share jukka_j's confusion why this should help, but moving the response out of the scope in a variable seems to make sure it still exists.
    We are using the 2019.4.9 (LTS) release, and would love to see this as an official LTS update, to avoid having to overwrite this file every LTS update.