Skip to content

WebGL Build Fails with Rive When "Target WebAssembly 2023" is Enabled #138

@VirtualMaestro

Description

@VirtualMaestro

Environment

Unity Version: 6000.3.2f1
Rive Runtime Version: v0.4.1-canary.6
Operating System: Windows 10 x64
Target Platform: WebGL Desktop
Build Configuration: Debug/Release (occurs in both)

Summary
WebGL builds fail during the linking phase with an LLVM error when "Target WebAssembly 2023" is enabled in Player Settings and Rive assets are included in the project. The error occurs specifically in the rive_png_free_jmpbuf function during WebAssembly instruction selection.
Steps to Reproduce

Create a new Unity 6000.3.2 project
Install Rive Runtime v0.4.1-canary.6 from Package Manager
Add any Rive file (.riv) to the project
Create a scene that uses the Rive asset (even a simple RiveScreen component)
Open Edit → Project Settings → Player → WebGL Settings
Under Publishing Settings, enable "Target WebAssembly 2023"
Attempt to build for WebGL platform

Expected Behavior
The build should complete successfully and produce a working WebGL build with Rive animations functioning correctly.
Actual Behavior
The build fails with the following error:
LLVM ERROR: Cannot select: 0x1ebda4b8568: ch = catchret 0x1ebcef57968, BasicBlock:ch< 0x1ebf4934a90>, BasicBlock:ch< 0x1ebf4934988>
In function: rive_png_free_jmpbuf

Stack dump:
0. Program arguments: "C:/Program Files/Unity/Hub/Editor/6000.3.2f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/llvm\wasm-ld.exe"

  1. Running pass 'Function Pass Manager' on module 'ld-temp.o'.
  2. Running pass 'WebAssembly Instruction Selection' on function '@rive_png_free_jmpbuf'

emcc: error: '"C:/Program Files/Unity/Hub/Editor/6000.3.2f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/llvm\wasm-ld.exe"' failed (returned 2147483651)
Workaround
Disable "Target WebAssembly 2023" in Player Settings → WebGL → Publishing Settings.
The following settings work correctly:

✅ Use WebAssembly.Table: Enabled
✅ Enable BigInt: Enabled
❌ Target WebAssembly 2023: Disabled (must be off)

Root Cause Analysis
The Rive Runtime includes precompiled native C++ libraries that use setjmp/longjmp for exception handling in the PNG decoding code. When "Target WebAssembly 2023" is enabled, Unity's Emscripten toolchain uses the new WebAssembly exception handling proposal, which is incompatible with the traditional setjmp/longjmp approach used in Rive's precompiled libraries.
The LLVM linker fails to generate WebAssembly instructions for the catchret operation because the native code wasn't compiled with the appropriate exception handling flags for the WebAssembly 2023 standard.
Technical Details

Failing function: rive_png_free_jmpbuf (PNG library within Rive Runtime)
Failure point: WebAssembly Instruction Selection pass in LLVM
Related: This affects any Rive functionality that uses PNG texture decoding
Emscripten version: The one bundled with Unity 6000.3.2f1

Suggested Fix
One of the following approaches should resolve this issue:

Rive Runtime: Recompile native libraries with WebAssembly 2023 exception handling support (requires -fwasm-exceptions flag in Emscripten)
Unity: Provide a better compatibility layer or an error message when incompatible native libraries are detected with WebAssembly 2023
Documentation: Add clear warnings about WebAssembly 2023 compatibility requirements for native plugins

Additional Notes

This issue is likely to affect other plugins using precompiled native code with setjmp/longjmp
The error only manifests when the project actually includes and uses Rive assets
Build succeeds without issues when WebAssembly 2023 is disabled
No runtime errors occur in the working build (WebAssembly 2020 mode)

Priority
High - Blocks WebGL deployment for any Unity 6 project using Rive with modern WebAssembly features enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions