Skip to content

[C#] [Unity 6] Added logic to use either getWasmTableEntry or dynCall for C# WebGL#4961

Open
rekhoff wants to merge 1 commit intomasterfrom
rekhoff/unity6-webgl-dyncall-fix
Open

[C#] [Unity 6] Added logic to use either getWasmTableEntry or dynCall for C# WebGL#4961
rekhoff wants to merge 1 commit intomasterfrom
rekhoff/unity6-webgl-dyncall-fix

Conversation

@rekhoff
Copy link
Copy Markdown
Contributor

@rekhoff rekhoff commented May 6, 2026

Description of Changes

This is a fix for #4959.

Unity 6 upgraded to a newer Emscripten version that removed the dynCall() library function. The SpacetimeDB C# SDK's WebSocket.jslib plugin used dynCall() in 6 places to invoke C# callbacks from JavaScript WebSocket events.

This PR adds a $WebSocketDynCall helper function that detects which API is available at runtime:

  • On Unity 6+: uses getWasmTableEntry(ptr).apply(null, args) (direct WASM function table access)
  • On Unity 2022 and earlier: uses the legacy dynCall(sig, ptr, args)

All dynCall call sites in WebSocket.jslib now route through this helper, ensuring we maintain backward-compatiblity.

API and ABI breaking changes

No breaking changes. This is a backward-compatible fix that works on both older and newer Unity versions.

Expected complexity level and risk

  1. Very low risk. The change is isolated to the WebGL jslib plugin and uses runtime feature detection to choose the appropriate calling mechanism. Both code paths are well-tested:
    • Unity 2022.3.62f2: uses legacy dynCall path
    • Unity 6000.4.5f1: uses getWasmTableEntry path

Testing

  • Create test server module with reducers and tables
  • Unity 2022.3.62f2 Editor: Connect and subscribe works
  • Unity 2022.3.62f2 WebGL Build: Connect and subscribe works
  • Unity 6000.4.5f1 Editor: Connect and subscribe works
  • Unity 6000.4.5f1 WebGL Build: Connect and subscribe works (was previously failing with dynCall is not defined)

@rekhoff rekhoff requested a review from JasonAtClockwork May 6, 2026 03:50
@rekhoff rekhoff self-assigned this May 6, 2026
@rekhoff rekhoff added bug Something isn't working bugfix Fixes something that was expected to work differently labels May 6, 2026
@rekhoff rekhoff marked this pull request as ready for review May 6, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working bugfix Fixes something that was expected to work differently

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant