-
Notifications
You must be signed in to change notification settings - Fork 17
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