Upgrade Unity project to 2021.3.5f1 now get webgl runtime loading errors

I upgrade our Unity project to 2021.3.5f1. Built iOS and run in testflight fine. Switch to WebGL and it runs fine in editor but when we build and and deploy the game fails to load.

We get this error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'apply')
    at Module.stackSave (webgl77.framework.js:3:324301)
    at invoke_iii (webgl77.framework.js:3:389988)
    at webgl77.wasm:0xa8d6a2
    at webgl77.wasm:0x68e4ed
    at callRuntimeCallbacks (webgl77.framework.js:3:23043)
    at initRuntime (webgl77.framework.js:3:14873)
    at doRun (webgl77.framework.js:3:411915)
    at run (webgl77.framework.js:3:412194)
    at runCaller (webgl77.framework.js:3:411121)
    at Object.removeRunDependency (webgl77.framework.js:3:16011)
    at webgl77.loader.js:1:5987

I saw this idea:

I tried that and it does get us past this error but then we get a bunch of different out-of-memory range runtime errors so not a solution for us.

We can’t upgrade past 2021.3.5 due to this error (I can’t believe Unity shipped multiple versions with this?): Unity Issue Tracker - UI Elements are no longer rendered when deactivating and reactivating the Parent GameObject. So, I can’t try anything newer than what we’re on.

We are using several plugins which I’m going to go through and disable and see if there’s any problems with them but does anyone have any suggestions for things we can try or a better way to debug what’s causing this type of error?

The issue you linked says “not reproduced with … 2022.1.9f1”.

It’s something you could try in a copy of the project, to upgrade it to 2022.1 and see if that particular issue goes away and at the same time how difficult it would be for you to upgrade the project in general to 2022.1.

You could also go through the changelogs of each version between these two to see if there’s any mention of a bugfix related to WebGL and TypeError. It’s possible you may find this fixed in an earlier version than what’s listed above. Even if that doesn’t help, sometimes these changelogs contain hints to what’s causing the issue (ie “causes TypeError in cases where …”) that might help you work around it in the current version.

Thanks @CodeSmile ! I don’t think it’s a unity version issue. I pulled down a unity sample project and changed all the build settings to match my project and it successfully built and ran. So - the unity version by itself seems to be OK and my configuration afaik matched so feels like this is a dependency/library problem that’s not getting pulled in correctly.

I have removed all the plugins from my project and still get this behavior.

But I have learned a couple things.

If I turn on exception handling with full stacktraces and embed debug symbols in player settings and build a release build then the game loads past the Unity loading screen - our initial loading screen displays. Then we get past the initial unity loading screen and our game starts initializing and then we get a crash. We use System.DateTime.now and that is failing and we get an exception thrown.

It’s basically exactly what is reported (and fixed) here: Unity Issue Tracker - DateTime.Now raises an exception in WebGL player
I pulled down a sample Unity project and dropped in a call to DateTime.now in a script and that loads and runs properly. So - it’s not a regression of that bug necessarily but it’s the exact same behavior.

A few other interesting things:

If I check ‘Development Build’ in the settings then the error goes away and the game runs fine. So, that probably means that we link against different libraries in development builds (the debug runtime libs?) and things work as expected there.

It’s maybe possible that there’s some initialization timing issue where in release builds (and the sample project) that there’s an initialization call that runs in the background that has different timing than in a debug build and we’re calling DateTime.now before the initialization is complete in release builds? That seems like a stretch - especially with WebGL being single threaded. But, I’m still kinda grasping at straws here.

Well, this was a giant waste of time and effort.

I just re-imported all assets in Unity (which I had already done before without any change in behavior) and now the crash is gone. I had tested on multiple computers in multiple browsers and with reloading unity and reimporting the project previously so I don’t know what is different now. But the game now runs as expected.

The WebGL toolchain in Unity is sooooo brittle it’s beyond frustrating. Unity needs to invest in a serious increase in QA before a competitor starts doing this right!

As you just found out, it’s best practice to delete your library folder whenever upgrading to a new Unity version, especially with WebGL.

Surprised Unity doesn’t just force it by default at this point.