twiddlingbits / twr-wasm

twr-wasm: easily run C/C++ code in a web browser using Web Assembly, with examples
https://twiddlingbits.dev/
MIT License
19 stars 2 forks source link

after adding twrLibrary, Async examples fail on FireFox #28

Closed twiddlingbits closed 1 month ago

twiddlingbits commented 2 months ago

(moving the conversation on this from email to github)

Jonathon Reports:

  1. after adding twrLibrary, Async examples fail on FireFox
  2. Works okay on Chrome
  3. Anthony was unable to reproduce the bug using FireFox on windows.
    • I was unable to get the async examples to work when running from local file system (using launch.json entry below). Not the issue that Johnathon had. My issue here is that SharredArrayBuffers are not enabled.
    • I was able to run them fine using python examples/server.py when in the twr-wasm root folder (this is how i run the local web server, and is what is listed in the docs)
  4. Johnathon was able to get the async examples to run when launching from "one level up in the folder hierarchy" (not sure exactly what this means as far as the root folder).

next step: Anthony asked Jonathan to try and debug the issue

Johnathon, take a look at twrmodasync.ts:

      const url=new URL('twrmodasyncproxy.js', import.meta.url);
      this.myWorker = new Worker(url, {type: "module" });
      this.myWorker.onerror = (event: ErrorEvent) => {
         console.log("this.myWorker.onerror (undefined message typically means Worker failed to load)");
         console.log("event.message: "+event.message)
         throw event;
      };

Here is the launch.json file that does not work for me. It does run the index.html file, but it does not enable SharedArrayBuffers. I did install the firefox debug VS Code extension. Any ideas?

{
    "configurations": [
   {
      "type": "firefox",
      "request": "launch",
      "reAttach": true,
      "name": "Launch Examples firefox",
      "file": "${workspaceFolder}/examples/index.html",
      "firefoxArgs": [
         "--enable-features=SharedArrayBuffers"
       ]
   },
JohnDog3112 commented 2 months ago

Clarification on one folder up: It wasn't working when I ran it like this: [~/Programming/twr-wasm]$ python3 examples/server.py Website loads as localhost:8000/examples

But it did work with this: [~/Programming/]$ python3 twr-wasm/examples/server.py Website loads as localhost:8000/twr-wasm/examples

I cleared history and site data on Firefox and it works fine from localhost:8000/examples, so I believe it was a caching issue. However, it might be worth figuring out how to prevent Firefox from caching the examples.