Compressed WEBGL Build fails loading

Hello!

I have this problem going on for 6 months now: My WEBGL game won’t load completly when I am using the Gzip or Brotli compression.

The loading bar fills up to 90%, then when loading the data file, I get this error:

Uncaught (in promise) RangeError: too many arguments provided for a function call […]/game.loader.js:1

This doesn’t happen when the game is not compressed, but I need to reduce the size of my game as much as I can, and compression really is the best solution for that…

Anyone have an idea of where this can come from?
Thank you!

This problem is persisting for more than 6 months now…

I started to try to understand what happen in the loader.js, so I auto-indented it and found that the error was throwed in this, line 21 :

 function d() {
        i().then(function(e) {
            e(u)
        });
        var e = s("dataUrl");
        u.preRun.push(function() {
            u.addRunDependency("dataUrl"), e.then(function(e) {
                var t = new DataView(e.buffer, e.byteOffset, e.byteLength),
                    r = 0,
                    n = "UnityWebData1.0\0";
                if (!String.fromCharCode.apply(null, e.subarray(r, r + n.length)) == n) throw "unknown data format";
                r += n.length;
                var o = t.getUint32(r, !0);
                for (r += 4; r < o;) {
                    var a = t.getUint32(r, !0);
                    r += 4;
                    var s = t.getUint32(r, !0);
                    r += 4;
                    var i = t.getUint32(r, !0);
                    r += 4;
                    var d = String.fromCharCode.apply(null, e.subarray(r, r + i));
                    r += i;
                    for (var l = 0, c = d.indexOf("/", l) + 1; c > 0; l = c, c = d.indexOf("/", l) + 1) u.FS_createPath(d.substring(0, l), d.substring(l, c - 1), !0, !0);
                    u.FS_createDataFile(d, null, e.subarray(a, a + s), !0, !0, !0)
                }
                u.removeRunDependency("dataUrl")
            })
        })
    }

Precisly here :

var d = String.fromCharCode.apply(null, e.subarray(r, r + i));

Where e is a Uint8array of 70011211 values, so i’m guessing it’s my whole data file. r is 32, and r+i is the size of the rest of the array…
So the problem seems to be that 70 millions arguments (~70mo .data file) is to much for that fromCharCode function, but it doesn’t make much sens…

I don’t know if I’m getting to far with this…

Anyone has an idea if this is the problem ?

Just a guess…
Is your Project Settings/Decompression Fallback ticked?

Else you have to have your server set up correctly, to broadcast the compression type in its header for the browser (this is new in 2020.1).
I’ve been dealing with buttload of similar errors these days, and it’s behaving somewhat reasonably now (webgl builds loading on different platforms). The other thing is, the 90% ‘done’ - i always experienced it with ‘Developer Tools’ (firefox) open, but that was an ‘out of memory’ error. Same error with Chrome and it’s dev tools open (closing dev tools while the site loads [or reloads] solves this issue in that case).

Nothing else i can think of right now, but will come back if i remember something. I’d love to help, seeing as i myself have created like 10 threads in different places in the past 3 days, asking for help and not a single answer in either. Damn, don’t want anyone else to suffer as much, ain’t pretty :).

Also, 2020.1 has changed the WebGL output , the whole loader was updated - so you might wanna check it out (or check out the previous version, which ever you are not using), if that solves your problem.

1 Like

Hello Stending,

I was having the same issue. This is what fixed it for me:

The response header of the file “Build.data.gz” had the “Content-Type” “x-gzip”. This caused the problem. I changed the “Content-Type” to “application/octet-stream”. I got the hint here: Unity - Manual: WebGL: Server configuration code samples

More concretely I added this to my .htaccess file (Apache config):

Add data type header

<FilesMatch “.(data.gz)$”>
Header set Content-Type “application/octet-stream”

I hope this helps. Greetings!

3 Likes

The issue here is likely that the web server is not properly configured to serve the pre-compressed file with correct compression header set.

The way this should work is that if you have a precompressed data file foo.data.gz on disk, the web server should be serving it to the client with the headers

Content-Encoding: gzip
Content-Type: application/octet-stream

In Apache and IIS this is achieved with the configuration that @paddyesch links to above. For nginx, one can use the following configuration:

        location ~ .+\.data\.br$ { add_header Content-Encoding br; }
        location ~ .+\.js\.br$ {
            add_header Content-Encoding br;
            default_type application/javascript;
        }
        location ~ .+\.wasm\.br$ {
            add_header Content-Encoding br;
            default_type application/wasm;
        }

        location ~ .+\.data\.gz$ { add_header Content-Encoding gzip; }
        location ~ .+\.js\.gz$ {
            add_header Content-Encoding gzip;
            default_type application/javascript;
        }
        location ~ .+\.wasm\.gz$ {
            add_header Content-Encoding gzip;
            default_type application/wasm;
        }

If you do not have the access to the web server to configure it, and the web server webadmin refuses to do it properly (although they shouldn’t, since its their bandwith and server resources in question here), you can as a last resort enable the Decompression Fallback option in the Unity project build settings. That option will unfortunately noticeably reduce startup time performance, and is generally unfeasible on mobile devices, which is why it is disabled by default since Unity 2020.1.

1 Like

I’ve been struggling with this issue today.

@jukka_j 's answer is correct but I had to clear the cache of the website to make it work. Took me hours to realize.

Just had the same issue but with the compression stuff set-up from the get go.
Turns out my problem was that i was building the project into a folder that had spaces in its name. All of the files in the “Build” subdirectory get named the same as the root folder (ex. “folder name.data.gz”), which seems to have caused the issue. After i built it again into a folder with no spaces it just worked. Renaming the files by hand might work too but i re-built the entire thing just to be sure.

1 Like

Hello,
I’m having that same error:

My web server configuration seems fine:

I’m using Unity 2021.1.7, no decompression fallback. What else could be the problem?

This actually fixed the issue for me

In my case Decompression Fallback does the trick! Thank you.