-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document that Context
can't be locked on Wasm
#2812
Comments
Context
can't be shared between threads on WasmContext
can't be locked on Wasm
Looks like if you unpin rust toolchain and build the demo with
Build using |
This doesn't look like the same issue, the blocking error the browser throws doesn't actually go through Rusts panic handler. |
When I wrote |
We could indeed just use But it would still need to be documented that you can only share it between workers on Wasm, because you can't lock in the main thread. I don't think this is solvable unless |
I recently adjusted a cross-platform game engine that uses Egui to support multi-threading on Wasm and noticed that it will panic almost immediately with "already mutably borrowed" which I knew about but was wondering why it worked just fine on native targets.
After some digging I found out that the issue is that on native targets it's using
RwLock
but on Wasm it's usingatomic_refcell
, which was kinda fine because multi-threaded Wasm is available on nightly only and barely anybody is using it (I assume). But obviously this means that it can't wait for a non-existent lock to release, it will just panic.To make Egui usable with Wasm on the main thread (the document), there is no real fix, as waiting is not possible there, see #1401.
I was actually surprised that my implementation was locking in the first place, nothing wrong with Egui there, it's documented, I just didn't notice. So I'm kind of a big proponent of #1399 now.
In the meantime I think it could be useful to mention the difference between native and Wasm somewhere. Happy to make a PR, just really don't know exactly where to put that.
The text was updated successfully, but these errors were encountered: