[ENGINE ONLY] WASM error

Hi, I got the following error from playcanvas.js when loading Basis (texture compression) module:

Module settings are:

const PRELOAD_MODULES = [
    { 'moduleName': 'BASIS', 'glueUrl': 'js/basis.wasm.js', 'wasmUrl': 'js/basis.wasm.wasm', 'fallbackUrl': 'js/basis.js', 'preload': false },
    { 'moduleName': 'Ammo', 'glueUrl': 'js/ammo.wasm.js', 'wasmUrl': 'js/ammo.wasm.wasm', 'fallbackUrl': 'js/ammo.js', 'preload': true },
];

And I load/initialize Basis like this

pc.basisDownload(
          moduleBasis.glueUrl,
          moduleBasis.wasmUrl,
          moduleBasis.fallbackUrl,
          callback()
        );

If you run the engine Basis example on GitHub and open Chrome Dev Tools, you don’t get that error. If you look at the Network tab, you’ll see that basis.wasm.wasm is served with a Response Header with Content-Type: application/wasm.

But if I just run a vanilla Apache web server on my local machine, I get:

You’ll see that Content-Type is missing from the response header. And in the console, the exception is thrown:

I believe this is why stream compilation of the WASM module fails. So it’s really a server configuration issue. If you set up .wasm with an application/wasm mime type in your server configuration, I suspect this will be solved.

2 Likes

Thanks @will, very true, I also found this out. But I must come up with a solution for my probject as it need to compile for production. This is been done using Webpack. The whole today I was figuring out whats going on and soon will come up with a solution. In my case it will be a Webpack config change for Vue.js. Also if someone is interested I found this very useful:

Isn’t it irrelevant whether you’re using Webpack or something else? This is a server mime type configuration issue. So, say, if you were using Apache, you’d consult:

https://httpd.apache.org/docs/2.4/mod/mod_mime.html#addtype

Yes if you are talking about remote it is of course so. But local def servers must also support it.
And also I faced issues with deploying to Netlify with is my go to continues deployment chain.

I should probably mention that stream compilation of WASM is really just an optimization (where compilation can start before download completes). Even if it fails, it should just fall back to compiling after download of the WASM module is fully complete.

2 Likes

Thank you @will honstly I had no glue what that all ment, I am at the beginning of those things :slight_smile:

Bu I get finally my Basis texture compression to work (temporary link, will be merged after more testing)
https://optimistic-mahavira-788ca3.netlify.app/#/playcanvas

2 Likes

Thx for that direction. I am hosting our apps on a AWS apache and a simple .htaccess file with the necessary entry removed the error:

AddType application/wasm .wasm

5 Likes