laundmo/bevy-spatial

Use on the web

tad-lispy opened this issue · 4 comments

Thank you for developing bevy-spatial. It's very promising. I'm trying to use it with my web game, but I'm getting a runtime error:

panicked at 'The global thread pool has not been initialized.: ThreadPoolBuildError { kind: IOError(Error { kind: Unsupported, message: "operation not supported on this platform" }) }', /home/tad/.cargo/registry/src/github.com-1ecc6299db9ec823/rayon-core-1.9.3/src/registry.rs:170:10

I read https://github.com/rayon-rs/rayon/tree/4d36131d047db5906c04b986120af56224321a62#usage-with-webassembly and tried to apply the steps described there, but since I am relatively new to Rust and WASM, I wasn't able to apply the advise. The project I'm working on is using Trunk.

Hey, thanks for bringing this to my attention.

Since Rayon is only optionally used for kd-tree, it should be quite easy to make it a feature in bevy-spatial too. Would that work for you? it might compromise on performance a bit - kd-tree is about 2 or 3 times faster with rayon.

Yes, I think that would be better. Of course the faster it goes, the better, but somewhat faster is better than not working 😁 So if it's not possible (or not easy) to get KD tree with Rayon working on the web, than making it an optional feature would be a big improvement.

Maybe one thing to consider is the following. Will it be possible to disable this feature for WASM target, but enable for other platforms? I'm not there yet, but eventually I would like to build the web version of my game, as well as native, from the same codebase. Then it would be great to use the rayon feature on supported platforms and disable it otherwise.

good news! release coming soon!
it is a lot slower than on desktop, but that was to be expected

image
(oops, didn't mean to close)