Skip to content

Improve C# WASM Runtime Binding Loading and Logging - #153

Closed
himanshigaba22 wants to merge 1 commit into
thoth-tech:mainfrom
himanshigaba22:csharp-wasm-runtime-fixes
Closed

Improve C# WASM Runtime Binding Loading and Logging#153
himanshigaba22 wants to merge 1 commit into
thoth-tech:mainfrom
himanshigaba22:csharp-wasm-runtime-fixes

Conversation

@himanshigaba22

Copy link
Copy Markdown

Overview

Follow-up fixes for the C# WASM runtime used in SplashKit Online, focused on
removing unsafe binding logic, improving debuggability, and extending partial
C# binding support.

Issues addressed

  • CSP-related failures caused by eval() usage in main.js
  • No visibility into which SplashKit bindings failed to resolve
  • process_events had no fallback if the binding was ever missing
  • DrawCircle had no C# binding at all — filtered out by bindingGenerator.py
    because it takes a color parameter, which isn't supported by JSImport's
    source-generated marshalling

Changes

CSharpWasmExpo/main.js

  • Replaced eval(name) with a direct globalThis[name] lookup — avoids CSP
    unsafe-eval restrictions and removes arbitrary code execution
  • Added logging for how many/which bindings resolved vs. failed
  • Added a no-op fallback for process_events so a missing binding degrades
    gracefully instead of crashing
  • Fixed a latent crash where compiler-error parsing assumed a fixed message
    format
  • Runtime errors are now also reported back to the IDE via reportError,
    not just logged to console

CSharpWasm/SplashKitBindings.Generated.cs

  • Added partial bindings for DrawCircle and RgbaColor, representing
    colour as a packed int (RGBA) since JSImport doesn't support marshalling
    arbitrary structs like SplashKit's color type
  • Verified via local build (buildAndCopy.sh) after correcting an initial
    uint return type to int (uint isn't marshallable — SYSLIB1072)

Known follow-up (not fixed here)

While testing, found that OpenWindow has no C# binding either — same root
cause (Window is in the generator's unsupported_types filter). The C#
backend currently has no way to explicitly open a window through bindings.
Worth its own follow-up item.

Testing

Built and ran locally via CSharpWasm/buildAndCopy.sh + npm run server.
Confirmed in browser DevTools console:

  • [SKO C# Runtime] Resolved 777/908 SplashKit bindings.
  • [SKO C# Runtime] .NET WASM runtime ready.
  • No eval/CSP-related errors
  • DrawCircle/RgbaColor compile and execute without error via a test
    C# program (using ClearScreen() in place of OpenWindow due to the
    gap noted above)

@github-actions

Copy link
Copy Markdown
🐋 PR Preview!
The preview is no more!
Congrats if this was merged! 😄

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.

1 participant