Exception thrown: RuntimeError: unreachable,RuntimeError: unreachable

Hello everyone.

I want to create a WebGL version of one of my Android games.
I am using Unity 2021.3.12f1 Apple Silicon.

The first and second scenes get loaded fine. But as soon as I click with the mouse cursor following error occurs in Chrome and Safari:

An error occurred running the Unity content on this page. See your browser JavaScript console for more info. The error was:
abort() at jsStackTrace@http://localhost:59016/Build/WebGL.framework.js:1267:23
stackTrace@http://localhost:59016/Build/WebGL.framework.js:1288:23
abort@http://localhost:59016/Build/WebGL.framework.js:38:54
___cxa_allocate_exception@http://localhost:59016/Build/WebGL.framework.js:2938:7
wasm-stub@[wasm code]

<?>.wasm-function[il2cpp::vm::Exception::Raise(Il2CppException*, MethodInfo*)]@[wasm code] <?>.wasm-function[il2cpp_raise_exception]@[wasm code] <?>.wasm-function[scripting_raise_exception(ScriptingExceptionPtr)]@[wasm code] <?>.wasm-function[Input_CUSTOM_GetTouch_Injected(int, Touch&)]@[wasm code] <?>.wasm-function[Input_GetTouch_Injected_m04E25DD035583531339AB310FBDD4F5A30817F87]@[wasm code] <?>.wasm-function[Input_GetTouch_m75D99FE801A94279874FA8DC6B6ADAD35F5123B1]@[wasm code] <?>.wasm-function[GameController2_Update_m2016C88A6DC3907F0A690187AC0541C086EA27AE]@[wasm code] <?>.wasm-function[RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915(void (*)(), MethodInfo const*, void*, void**, void*)]@[wasm code] <?>.wasm-function[il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)]@[wasm code] <?>.wasm-function[dynCall_iiii]@[wasm code]

wasm-stub@[wasm code]
52229@[native code]
@http://localhost:59016/Build/WebGL.framework.js:1048:25
invoke_iiii@http://localhost:59016/Build/WebGL.framework.js:14116:22
wasm-stub@[wasm code]

<?>.wasm-function[il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**)]@[wasm code] <?>.wasm-function[il2cpp_runtime_invoke]@[wasm code] <?>.wasm-function[scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool)]@[wasm code] <?>.wasm-function[ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool)]@[wasm code] <?>.wasm-function[MonoBehaviour::CallUpdateMethod(int)]@[wasm code] <?>.wasm-function[MonoBehaviour

Here is the error in the console:

exception thrown: RuntimeError: unreachable,RuntimeError: unreachable
at il2cpp::vm::Exception::Raise(Il2CppException*, MethodInfo*) (http://localhost:59016/Build/WebGL.wasm:wasm-function[1730]:0xa79f7)
at il2cpp_raise_exception (http://localhost:59016/Build/WebGL.wasm:wasm-function[35628]:0x6ab4bf)
at scripting_raise_exception(ScriptingExceptionPtr) (http://localhost:59016/Build/WebGL.wasm:wasm-function[51341]:0xe9e481)
at Input_CUSTOM_GetTouch_Injected(int, Touch&) (http://localhost:59016/Build/WebGL.wasm:wasm-function[50962]:0xe80be5)
at Input_GetTouch_Injected_m04E25DD035583531339AB310FBDD4F5A30817F87 (http://localhost:59016/Build/WebGL.wasm:wasm-function[7845]:0x22b2e3)
at Input_GetTouch_m75D99FE801A94279874FA8DC6B6ADAD35F5123B1 (http://localhost:59016/Build/WebGL.wasm:wasm-function[7844]:0x22b2a1)
at GameController2_Update_m2016C88A6DC3907F0A690187AC0541C086EA27AE (http://localhost:59016/Build/WebGL.wasm:wasm-function[30219]:0x60135d)
at RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915(void ()(), MethodInfo const, void*, void**, void*) (http://localhost:59016/Build/WebGL.wasm:wasm-function[34392]:0x694ed2)
at il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**) (http://localhost:59016/Build/WebGL.wasm:wasm-function[35591]:0x6aa14c)
at dynCall_iiii (http://localhost:59016/Build/WebGL.wasm:wasm-function[52229]:0xeeddc9)
at http://localhost:59016/Build/WebGL.framework.js:1048:20
at invoke_iiii (http://localhost:59016/Build/WebGL.framework.js:14116:10)
at il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) (http://localhost:59016/Build/WebGL.wasm:wasm-function[35566]:0x6a9851)
at il2cpp_runtime_invoke (http://localhost:59016/Build/WebGL.wasm:wasm-function[35637]:0x6ab8e6)
at scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) (http://localhost:59016/Build/WebGL.wasm:wasm-function[51423]:0xea5192)
at ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) (http://localhost:59016/Build/WebGL.wasm:wasm-function[50213]:0xe48145)
at MonoBehaviour::CallUpdateMethod(int) (http://localhost:59016/Build/WebGL.wasm:wasm-function[50159]:0xe444a9)
at MonoBehaviour::Update() (http://localhost:59016/Build/WebGL.wasm:wasm-function[50160]:0xe444be)
at void BaseBehaviourManager::CommonUpdate() (http://localhost:59016/Build/WebGL.wasm:wasm-function[38361]:0x739f3b)
at BehaviourManager::Update() (http://localhost:59016/Build/WebGL.wasm:wasm-function[38360]:0x739cbc)
at InitPlayerLoopCallbacks()::UpdateScriptRunBehaviourUpdateRegistrator::Forward() (http://localhost:59016/Build/WebGL.wasm:wasm-function[49922]:0xe200cb)
at ExecutePlayerLoop(NativePlayerLoopSystem*) (http://localhost:59016/Build/WebGL.wasm:wasm-function[38190]:0x728cb2)
at ExecutePlayerLoop(NativePlayerLoopSystem*) (http://localhost:59016/Build/WebGL.wasm:wasm-function[38190]:0x728d4e)
at MainLoop() (http://localhost:59016/Build/WebGL.wasm:wasm-function[47974]:0xd04e82)
at dynCall_v (http://localhost:59016/Build/WebGL.wasm:wasm-function[52225]:0xeedd8e)
at http://localhost:59016/Build/WebGL.framework.js:1048:20
at browserIterationFunc (http://localhost:59016/Build/WebGL.framework.js:9380:13)
at callUserCallback (http://localhost:59016/Build/WebGL.framework.js:7570:3)
at Object.runIter (http://localhost:59016/Build/WebGL.framework.js:7631:4)
at Browser_mainLoop_runner (http://localhost:59016/Build/WebGL.framework.js:7545:20)

Can you try doing a build with Enable Exceptions: ā€œFull with Stacktraceā€? (or Full without Stacktrace to get smaller builds)

9260649--1295649--upload_2023-8-30_14-14-25.png

To save on code size, exception handling is heavily stripped down by default.

1 Like

I have now enabled exceptions ā€œFull with Stacktraceā€.

And I have changed this code which handles the click:

// click the left mouse button to drop the piece into the selected column
                    if (Input.GetMouseButtonDown(0) && !mouseButtonPressed && !isDropping)
                    {
                        // Only if mouse is not over UI in editor
#if UNITY_EDITOR
                        if (!EventSystem.current.IsPointerOverGameObject())
#endif
                        // Only if finger is not over UI on mobile
#if !UNITY_EDITOR
                        if (
                            !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)
                        )
#endif
                        {
                            mouseButtonPressed = true;
                            // Show gameObjectTurn when clicked
                            gameObjectTurn.GetComponent<Renderer>().enabled = true;
                            StartCoroutine(dropPiece(gameObjectTurn));
                        }
                    }

to this new code:

// click the left mouse button to drop the piece into the selected column
                    if (Input.GetMouseButtonDown(0) && !mouseButtonPressed && !isDropping)
                    {
                        // Only if mouse is not over UI in editor
#if UNITY_EDITOR || UNITY_WEBGL
                        if (!EventSystem.current.IsPointerOverGameObject())
#endif
                        // Only if finger is not over UI on mobile
// #if !UNITY_EDITOR
//                         if (
//                             !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)
//                         )
// #endif
                        {
                            mouseButtonPressed = true;
                            // Show gameObjectTurn when clicked
                            gameObjectTurn.GetComponent<Renderer>().enabled = true;
                            StartCoroutine(dropPiece(gameObjectTurn));
                        }
                    }

Now the clicking works but than I have the following error which I never have in the editor:

NullReferenceException: Object reference not set to an instance of an object.
at ConnectFour.GameController2.SpawnPiece () [0x00000] in <00000000000000000000000000000000>:0
at ConnectFour.GameController2.Update () [0x00000] in <00000000000000000000000000000000>:0

That error suggests that some object is null at runtime. I notice there are a few UNITY_EDITOR specific branches in the code, so possibly the same code is not executed in editor vs in a web build. Maybe that is leading to the discrepancy.

Thanks jukka. At the moment the same code gets executed in the editor and in the web build.
I have commented out the editor specific code…