Skip to content

Conversation

@NickKhalow
Copy link
Contributor

@NickKhalow NickKhalow commented Jan 21, 2026

WebGL runs in a single-threaded environment and does not support System.Threading, System.Threading.Tasks, blocking synchronization primitives, file system access, or native sockets.
This PR removes or gates incompatible APIs, replaces them with WebGL-safe abstractions, and enforces compile-time correctness to prevent regressions.

Summary of Changes

Threading & Synchronization

  • Removed direct usage of System.Threading primitives (SemaphoreSlim, Interlocked, thread pool usage).
  • Introduced WebGL-safe wrappers (DCLSemaphoreSlim, DCLInterlocked, DCLTask).
  • MultiThreadSync and ECS locking systems are excluded from WebGL builds (#if !UNITY_WEBGL), as WebGL execution is single-threaded by design.
  • Static analysis markers added to explicitly acknowledge WebGL thread-safety assumptions where unavoidable.

Task to UniTask migration

  • Eliminated System.Threading.Tasks usage across runtime and infrastructure code.
  • Replaced Task / ValueTask APIs with UniTask.
  • GLTFast integrations are fully excluded from WebGL builds due to hard dependency on Task.

WebGL platform gating

  • Explicitly excluded unsupported systems from WebGL:

    • Disk cache & file-system–based caches
    • Deep link handling
    • GLTF loading pipeline
    • Terrain rendering
  • Introduced IDiskCache.Null for WebGL to preserve API shape without runtime side effects.

WebSocket / networking

  • Reworked WebSocket runtime to avoid Task and thread-based synchronization.
  • Replaced SemaphoreSlim and Interlocked with WebGL-safe equivalents.
  • Prepared ground for JS-based WebSocket / Socket.IO bridge (follow-up work).

Authentication & bootstrap cleanup

  • Simplified Web3 authentication flow:

    • Replaced IWeb3VerifiedAuthenticator with IWeb3Authenticator.
    • Removed global verification listeners; verification callbacks are now passed explicitly.
  • Adjusted auto-login and bootstrap flows to the new async model.

Tests & assembly definitions

  • Updated tests to conditionally include threading constructs only on non-WebGL platforms.
  • Fixed asmdef references to reflect new dependencies introduced by threading abstractions.

Debugging & diagnostics

  • Added explicit debug trace points to diagnose silent WebGL execution stalls.
  • No behavioral changes outside WebGL; logs are temporary and scoped.

Why this change

  • Prevents silent runtime hangs in WebGL caused by unsupported threading APIs.
  • Enforces compile-time safety instead of relying on runtime failures.
  • Establishes a clear boundary between desktop and WebGL execution models.
  • Unblocks further WebGL work (JS bridges, WebWorkers, networking).

Follow-ups

  • JS bridge for WebSocket / Socket.IO.
  • Removal or refactor of remaining file-system–dependent systems.
  • Cleanup of temporary debug logs once WebGL stability is confirmed.

@NickKhalow NickKhalow self-assigned this Jan 21, 2026
@github-actions
Copy link
Contributor

badge

New build in progress, come back later!

@NickKhalow NickKhalow changed the title Feat/webgl build setup FeatT: WebGL, extract Threading/Task APIs, gate unsupported systems, and align async model Jan 21, 2026
@NickKhalow NickKhalow changed the title FeatT: WebGL, extract Threading/Task APIs, gate unsupported systems, and align async model Feat: WebGL, extract Threading/Task APIs, gate unsupported systems, and align async model Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants