Fyrox: wasm error with condvar mutex
I was able to run my game in editor and wasm_pack generated the wasm file without any issue. but when i run it in browser e.g. Chrome, it threw following errors:
panicked at ‘condvar wait not supported’, library/std/src/sys/wasm/…/unsupported/locks/condvar.rs:21:9
panicked at ‘assertion failed: (left == right)
left: true
,
right: false
: cannot recursively acquire mutex’, library/std/src/sys/wasm/…/unsupported/locks/mutex.rs:24:9
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (11 by maintainers)
Commits related to this issue
- `AsyncSceneLoader` - cross-platform (wasm included) asynchronous scene loader - part of #404 — committed to FyroxEngine/Fyrox by mrDIMAS 2 years ago
- use `AsyncSceneLoader` in `Executor` - prevents panic on wasm targets - part of #404 — committed to FyroxEngine/Fyrox by mrDIMAS 2 years ago
- added support for wasm in fyrox-template - now fyrox-template generates `executor-wasm` crate which is a special version of executor for webassembly - part of #404 — committed to FyroxEngine/Fyrox by mrDIMAS 2 years ago
- non-blocking resource waiting before processing scene scripts - part of #404 — committed to FyroxEngine/Fyrox by mrDIMAS 2 years ago
WebAssembly is kinda annoying, the fact that you cannot block to execute a future is sad. However, there’s one good thing about this - having non-blocking code will make your app much better from user perspective. You can draw a progress bar, or some other stuff while game’s assets are loading.
The issue should be fixed, I got @invokermain 's project running in both Firefox and Chrome:
@invokermain If you have any improvements to
executor-wasm
template, please make a PR 🙏@GOVYANSONG looks like you’re trying to get a reference to a non-loaded scene by a null-handle.
It turns out that there’s a handful of
block_on
s left in the engine code. I’ll try to fix that today.This is what I have after building
executor-wasm
and running it in Firefox:The idea is to remove any platform-specific code from user code. WebAssembly does not support
std::thread
(at least onwasm32-unknown-unknown
target) and it is only possible to spawn a background task with some custom actions. SoAsyncSceneLoader
is that cross-platform solution - internally it “off-threads” scene loading as a background task and providesfetch_result
method that can be used to obtain actual loading result (when it is ready).So first steps to fix the issue were made. New
AsyncSceneLoader
works fine with WebAssembly, now it is time to improvefyrox-template
- it needs a separateexecutor-wasm
project for WebAssembly.executor
itself cannot be modified (at least I don’t see how to do it), because WebAssembly requires very specific project structure:I hope I can add this today, this is interesting task and I’m eager to see some of my games (this one https://github.com/mrDIMAS/FishFolly specifically) working on WebAssembly targets.
I’ll try to fix that today.