"RangeError: Maximum call stack size exceeded" after Unity has loaded in WebGL

Hi,

I’m currently trying to solve above problem in our educational game project and I have come to a dead end with searching solutions all around internet.

Our team is trying to integrate Unity game in to our own system built and coded with Vaadin, Java and Javascript. The thing is that our game needs to take parameters as “setups” from our system and use them in the game and when game is done, send something back with callback function. This all works perfectly in the game and via the index file created during conversion to WebGL platform game, I can send parameters to the game and it works with those “setups”.However I have managed to encounter the above error when trying to integrate the game int to our system.

First I tried to do it with

This can currently happen in WebGL when it tries to find a function which is getting stripped (and then some code endlessly recurses trying to find that function). We are fixing this to do better error reporting, until then, try putting in some Debug prints in the code around where the issue happens, to find out what code it is calling, so you might see which function is getting stripped.

Okey, I tried to debug through the code from the init.js file and put some console.debugs through out the initialization function. It goes through it without problems but the RangeError comes after the game has gone through the initialization. That’s why I was so confused that where the error could come from. But should I still try to put some debugs in the game itself? I also took some pictures from the PlayerSettings of the game. The point is to get as small game package as possible so if you know some tricks to that too, let me know.

I ran into the same issue as well. Jonas, what do you mean by “stripped”?

One step closer to the error once again. I tried the console trick and took it further on. I put console.logs all over the UnityConfig.js and fileloader.js files and was able to locate one kind of source where it comes from. Here is the fileloader.js

function runWithFS() {
                console.log("Fileloader 24");
                function assert(check, msg) {
                    console.log("Fileloader 25");
                    if (!check) throw msg + new Error().stack;
                }
                Module['FS_createPath']('/', 'Resources', true, true);
                console.log("Fileloader 26");
                function DataRequest(start, end, crunched, audio) {
                    this.start = start;
                    this.end = end;
                    this.crunched = crunched;
                    this.audio = audio;
                    console.log("Fileloader 27");
                }
                DataRequest.prototype = {
                        requests: {},
                        open: function(mode, name) {
                            console.log("Fileloader 28");
                            this.name = name;
                            this.requests[name] = this;
                            Module['addRunDependency']('fp ' + this.name);
                        },
                        send: function() {},
                        onload: function() {
                            console.log("Fileloader 29");
                            var byteArray = this.byteArray.subarray(this.start, this.end);

                            this.finish(byteArray);

                        },
                        finish: function(byteArray) {
                            console.log("Fileloader 30");
                            var that = this;
                            Module['FS_createPreloadedFile'](this.name, null, byteArray, true, true, function() {
                                Module['removeRunDependency']('fp ' + that.name);
                            }, function() {
                                if (that.audio) {
                                    console.log("Fileloader 31");
                                    Module['removeRunDependency']('fp ' + that.name); // workaround for chromium bug 124926 (still no audio with this, but at least we don't hang)
                                } else {
                                    console.log("Fileloader 32");
                                    Module.printErr('Preloading file ' + that.name + ' failed');
                                }
                            }, false, true); // canOwn this data in the filesystem, it is a slide into the heap that will never change
                            this.requests[this.name] = null;
                        },
                };
                console.log("Fileloader 33");
                new DataRequest(0, 31356, 0, 0).open('GET', '/mainData');
                new DataRequest(31356, 31588, 0, 0).open('GET', '/methods_pointedto_by_uievents.xml');
                new DataRequest(31588, 4403916, 0, 0).open('GET', '/sharedassets0.assets');
                new DataRequest(4403916, 4410113, 0, 0).open('GET', '/sharedassets0.resource');
                new DataRequest(4410113, 5985149, 0, 0).open('GET', '/Resources/unity_default_resources');
                new DataRequest(5985149, 6485625, 0, 0).open('GET', '/Resources/unity_builtin_extra');
                console.log("Fileloader 34");
                function processPackageData(arrayBuffer) {
                    console.log("Fileloader 35");
                    Module.finishedDataFileDownloads++;
                    assert(arrayBuffer, 'Loading data file failed.');
                    var byteArray = new Uint8Array(arrayBuffer);
                    var curr;
                    console.log("Fileloader 36");
                    // Reuse the bytearray from the XHR as the source for file reads.
                    DataRequest.prototype.byteArray = byteArray;
                    DataRequest.prototype.requests["/mainData"].onload();
                    DataRequest.prototype.requests["/methods_pointedto_by_uievents.xml"].onload();
                    DataRequest.prototype.requests["/sharedassets0.assets"].onload();
                    DataRequest.prototype.requests["/sharedassets0.resource"].onload();
                    DataRequest.prototype.requests["/Resources/unity_default_resources"].onload();
                    DataRequest.prototype.requests["/Resources/unity_builtin_extra"].onload();
                    Module['removeRunDependency']('datafile_CatchTheNumber.data');
                    console.log("Fileloader 37");
                };
                Module['addRunDependency']('datafile_CatchTheNumber.data');
                console.log("Fileloader 38");
                if (!Module.preloadResults) Module.preloadResults = {};
                console.log("Fileloader 39");
                Module.preloadResults[PACKAGE_NAME] = {fromCache: false};
                if (fetched) {
                    console.log("Fileloader 40");
                    processPackageData(fetched);
                    fetched = null;
                } else {
                    console.log("Fileloader 41");
                    fetchedCallback = processPackageData;
                }
                console.log("Fileloader 42");
            }
            if (Module['calledRun']) {
                console.log("Fileloader 43");
                runWithFS();
            } else {
                console.log("Fileloader 44");
                if (!Module['preRun']) Module['preRun'] = [];
                Module["preRun"].push(runWithFS); // FS is not initialized yet, wait for it
            }

Now I get the error somewhere around here:
(This is from my browsers console prints)
Fileloader 24
Fileloader 26
Fileloader 33
Fileloader 27
Fileloader 28
Fileloader 27
Fileloader 28
Fileloader 27
Fileloader 28
Fileloader 27
Fileloader 28
Fileloader 27
Fileloader 28
Fileloader 27
Fileloader 28
Fileloader 34
Fileloader 38
Fileloader 39
Fileloader 40
Fileloader 35
Fileloader 25
Fileloader 36
Fileloader 29
Fileloader 30
Fileloader 29
Fileloader 30
Fileloader 29
Fileloader 30
Fileloader 29
Fileloader 30
Fileloader 29
Fileloader 30
Fileloader 29
Fileloader 30
Fileloader 37
Fileloader 42
Invoking error handler due to
Uncaught RangeError: Maximum call stack size exceeded

Attached the console logs to different files, so it’s clearer to see the differents

2161282–142855–From js file.txt (1.34 KB)
2161282–142856–from iframe and index file.txt (3.26 KB)

We strip code which is not used during the build. However, sometimes, we cannot determine that a method or type is being used - typically when something is trying to call them by reflection by name, and may end up incorrectly stripping that code. You can use a link.xml file as described here to work around that: http://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html

So how about the reading order of the files. According to those files I posted earlier, the iframe has different reading order than when I’m trying to execute all from one js file. Any suggestions to that?

Oh right, thanks for the explanation. Just so everyone knows, in my case, the rangeerror was actually caused by a method that was throwing a null reference exception - once I fixed that, this error stopped appearing.

Also happens when trying to use Unity Analytics on WebGL…

And by use, I mean just having ‘using UnityEngine.Analytics’

Hi There,

I know this is old thread, this is happening to me now, has happened in past but resolved itself, so I’m not sure to wait it out or try troubleshoot. I need some help. I’ve scoured the web for a few days now on google and stack overflow etc. My game stopped working on WebGL after the Unity update 2018.1.0f2 Personal. Now WebGL fails, but runs in editor and PC builds fine. I have played around allot with the player settings to no avail. bosssoftaware.net/GLTrump.html. There are no errors in my code(from what i can tell), worked before the update.

Google Chrome gives error - Uncaught RangeError: Maximum call stack size exceeded.
Firefox gives error - too much recursion

My next step it to try debug chrome and firefox, but I am unsure and not sure if it is worth it, so if anyone know anything please inform me.

SOLVED. For me it was to set in the WebGL Player settings API Compatibility level to .Net Standard 2.0

1 Like

Instead of Creating a new Thread, I felt that this one was very relevant to what I was going through in Unity 2018.1.0f.

My Problem: I received the Range Error with a project that was a part of a series of simulations, they all are their own builds and runs similarly simulating different devices. So far everyone of them was working except for one particular project. I kept running into this error on Google Chrome. now I did not test it on any other browsers.

I tried to change the API Compatibility Level to .NET 2.0, not the subset. However I still ran into this error

Solution: After more research I found this thread Uncaught RangeError : Maximum Call Stack Size Exceeded after game loaded (hosted in azure) - Questions & Answers - Unity Discussions

The first response declared that Clearing Chrome’s Data fixed the problem. This worked for me, however I do not want my users to have to clear chrome’s data if they run into this error.

My Question: Is there a way where I can avoid this error all together?

1 Like

For me neither cleaning Chrome’s data nor changing the API compatibility level, didn’t worked for me, anyone knows if there is a bug report created?

I had similar problems with the Chrome browser, even with API Compatibility Level set to .NET 2.0. To fix it I went to the Resolution and Presentation settings of Player Settings and selected Minimal WebGL Template. Then rebuilt and redeployed.

Sorry for the bump but I think (fingers crossed) this solved the same “rangeerror maximum call stack” error I had (changing Scripting Runtime Version to 4.0 first, then Net Standard 2 became available as an Api Compatibility Level option), so I really appreciate you posting this as I don’t know if I would have figured that out myself. (I combined it with Raybosama’s suggestion of “Minimal WebGL Template” too just to be safe since I’m not close to being a pro at developing and debugging. :P) I’m still on 2018.2.11f1 so maybe that caused some issue(s).

I have a simple scene with two 3D models (Lowpoly Baker's House | 3D Fantasy | Unity Asset Store) and two dynamic lights. This scene loads fine on both desktop , android and iphones (total file size was under 5 MB). I added a single Text Mesh Pro label to the scene was updating it through code (sort of like a debug log but visible on screen) and this worked correctly on android and desktop. But when I try to run on safari or chrome on an iPhone 7 running ios version 13.1.1 it does not load. It shows the warning message (which it showed earlier too) and on pressing ok it proceeds to load the scene. It stops at about 90% with the following stack trace :

Warning: Unsupported graphics API WebGL 2.0
[UnityCache] 'http://192.168.0.179/webgl/Build/Web.wasm.code.unityweb' successfully revalidated and served from the indexedDB cache
[UnityCache] 'http://192.168.0.179/webgl/Build/Web.wasm.framework.unityweb' successfully revalidated and served from the indexedDB cache
[UnityCache] 'http://192.168.0.179/webgl/Build/Web.data.unityweb' successfully revalidated and served from the indexedDB cache
failed to asynchronously prepare wasm: Error: Out of executable memory in function at index 29257
Error: Out of executable memory in function at index 29257
Error: Out of executable memory in function at index 29257
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)
still waiting on run dependencies:
dependency: wasm-instantiate
(end of list)

It then shows a popup with the message “RangeError: Maximum call stack size exceeded”.

I have tried restarting the phone, clearing the cache, the scripting run-time version is set to .Net 4,x Equivalent, set the display to minimal as mentioned above, increased memory to 512 from 256 under Publishing settings. I have no idea what else to try. I have new to web development and hence have to idea on how to proceed ahead. Any help would be appreciated.

Try to clear browser cache (Ctrl+F5). Sometimes it helps with this bugs.

12 Likes

This is a painful issue we are very well aware of with older versions of Safari. These are reported as

https://bugs.webkit.org/show_bug.cgi?id=181723
https://bugs.webkit.org/show_bug.cgi?id=200686
https://bugs.webkit.org/show_bug.cgi?id=200807
https://bugs.webkit.org/show_bug.cgi?id=206284

The problem should be fixes in newer versions of Safari. If the issue still reproduces in latest Safari browsers, please let us know.

Thank you. This was all it took for me. Now. If only the Unity team can get gzip compression working properly with the Linux version of 2020.2 :slight_smile:

I was not aware of an issue on this front (granted, I don’t have a Linux development system available atm - another engineer is looking at Linux WebGL support for Unity 2021.2 release). Is there a specific error you get? I could route that by him if so.