Can we run Havok inside a Web Worker?

I’m able to load Havok WASM on the main thread using await HavokPhysics(). But, this throws an error inside a Web Worker:

RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -sASSERTIONS for more info.

Could anyone please share if they were able to run Havok inside a Web Worker?

For additional context, I’m able to load Ammo WASM successfully on both the main thread and in a Web Worker

I think this is indeed not possible currently, let me cc @eoin for confirmation

1 Like

There’s a couple of difficulties if you’re trying to use Havok from multiple web workers simultaneously, but I think it should be possible to use from just one (though, I haven’t tried.)

The error you’re seeing is because WASM modules expect to begin with a special identifier (\0asm) which does not appear in yours - instead, it has <!DO which looks like you’re trying to instantiate a WASM with an HTML page, rather than the module data?


Thanks, @carolhmj and @eoin !

@eoin Does running importScripts(<PATH_TO_HavokPhysics_umd.js>) and await HavokPhysics() inside a Web Worker script mean that I’m trying to instantiate a WASM with an HTML page, rather than the module data? Could you please share more details on how I can instantiate a WASM with the module data instead?

my two cents - it is trying to download the wasm file, but it is 404-ing, so you get an html page. When initializing the havok module you can pass the URL from which the wasm will be downloaded. might be the way to go here

1 Like

Ooh, thank you, @RaananW ! After passing in the wasm path, it seems to be working:

const HK = await HavokPhysics({ locateFile: () => <PATH_TO_HavokPhysics.wasm>});

awesome! :slight_smile:

1 Like