News for hackers. Stuff that matters.
Re:Show HN: Box2D fluid simulation in WebGL and WASM by Birch-san on Friday April 02, 2021 @05:20PM (#26676122)
Ah, if it's blank, then it blew up really early.

It sounds like it's complaining about the use of ES modules. This script is loaded with `<script type="module">` and uses ES imports (`import App from './App.svelte'`).

Yes, Safari is expected to go bang (doesn't support module Workers).

I target Chromium's featureset — I developed on macOS Edge. macOS Chrome and Android's Chrome WebView work for me too.

It needs a few modern features in order to work:

  - Web workers
  - WebAssembly
  - top-level await (on Web, and in Worker)
  - ES modules + imports (on Web, and in Worker)
  - requestAnimationFrame in Worker
  - WebGL2
  - OffscreenCanvas
Most of these were chosen for "ease of development". With bundling, it'd be possible to eliminate the ES modules / await usage. WebGL2 isn't strictly necessary either. WASM + workers are widely supported.

So the primary blocker to Firefox support is support for OffscreenCanvas, and requestAnimationFrame in Worker. There's other options there: render on the main thread instead. Harder to develop (syncing timing + state between threads). Can probably be done performantly with SharedArrayBuffer.

In truth, I did include error-handling to provide a compatibility explanation if the worker explodes. This displays in Firefox. But I hadn't expected the main thread to explode too.

Here's a GIF of what it's supposed to look like!

https://birchlabs.co.uk/box2d-wasm-liquidfun/liquidfun.gif

Re:Show HN: Box2D fluid simulation in WebGL and WASM by greggman3 on Friday April 02, 2021 @09:34PM (#26677690)
Re:Show HN: Box2D fluid simulation in WebGL and WASM by ranguna on Saturday April 03, 2021 @04:45AM (#26679346)
Very cool demo, works great on chrome mobile.

But I'm not sure using top level await was a good idea at this time. Can't really open it in Firefox mobile either (due to import syntax).

Re:Show HN: Box2D fluid simulation in WebGL and WASM by brundolf on Friday April 02, 2021 @08:31PM (#26677337)
I'm surprised it doesn't work on Firefox; it should have all of those features