rive-app / rive-app/rive-unity

WebGL Build Crashes with "RuntimeError: unreachable" When LTO is Enabled

Open
#140 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
205
Forks
22
PR merge metrics
No merged PRs in 30d

Description

Environment

Unity Version: 6000.3.2f1
Rive Runtime Version: v0.4.1-canary.6
Operating System: Windows 10 x64
Build Target: WebGL Desktop
Browser: (specify browser and version)

Summary
WebGL builds crash immediately on launch with RuntimeError: unreachable when Link Time Optimization (LTO) is enabled in Code Optimization settings. The build process completes successfully, but the application fails to start in the browser.
Steps to Reproduce

Create a Unity 6000.3.2 project with Rive Runtime v0.4.1-canary.6 (or take already created minimal project https://github.com/VirtualMaestro/Minimal_Rive_WebGL_Issue_Reproduction_Project)
Add Rive assets to the project
Open Build profiles -> choose Web - Desktop Release → Code Optimization, select either:

"Disk Size with LTO", OR
"Runtime speed with LTO"

Build for WebGL
Launch the build in a browser
Application crashes immediately during initialization

Expected Behavior
The application should launch and run normally with LTO optimizations applied, resulting in smaller build size or better runtime performance.
Actual Behavior
The application crashes during startup with the following error:
RuntimeError: unreachable
at http://localhost:59992/Build/Builds.wasm.br:wasm-function[80501]:0x230f06d
at invoke_iiiii (http://localhost:59992/Build/Builds.framework.js.br:9:349809)
at http://localhost:59992/Build/Builds.wasm.br:wasm-function[80504]:0x230fb66
at invoke_viiii (http://localhost:59992/Build/Builds.framework.js.br:9:350970)
[... additional stack trace ...]
The error occurs during WebAssembly module initialization, preventing the application from starting at all.
Working Configuration
The build works correctly when Code Optimization is set to:

✅ "Shorter build time"
✅ "Disk size" (without LTO)
✅ "Runtime speed" (without LTO)

Failing Configuration
The build crashes when Code Optimization is set to:

❌ "Disk Size with LTO"
❌ "Runtime speed with LTO"

Root Cause Analysis
The unreachable instruction in WebAssembly is inserted by the compiler in code paths that should theoretically never execute. This error typically indicates:

LTO optimization conflicts: Link Time Optimization aggressively inlines and optimizes across compilation units, which can break assumptions made by precompiled native libraries
Exception handling issues: LTO may misoptimize exception handling code paths in Rive's C++ runtime
ABI incompatibility: Rive's precompiled libraries may have been built with different optimization assumptions than Unity's LTO expects
Undefined behavior exposure: LTO's aggressive optimizations can expose latent undefined behavior in C++ code that works fine without optimization

Most likely cause: Rive Runtime's precompiled native libraries were not built with LTO-compatible flags, causing the linker to make incorrect assumptions during whole-program optimization.
Technical Details

Error type: RuntimeError: unreachable
Failure point: During WebAssembly module initialization
Affected code: Appears to be in Rive's native initialization routines (based on function indices in stack trace)
LTO behavior: Unity's Emscripten LTO performs cross-module inlining and dead code elimination

Impact

Severity: High (complete application failure)
Workaround availability: Yes (disable LTO)
Build size impact: Disabling LTO results in larger builds (~20-40% increase)
Performance impact: Disabling LTO may result in slower runtime performance

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Minimal_Rive_WebGL_Issue_Reproduction_Project and reproduce the failure in Unity 6000.3.2f1 using the two WebGL Code Optimization settings that enable LTO. Compare the browser initialization stack trace with non-LTO builds and document or fix the runtime behavior so both LTO configurations launch successfully without the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity, wasm
Domain
game-dev, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.