Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

std::time::Instant not supported by WebAssembly #1022

Closed
niklaskorz opened this issue Jan 1, 2022 · 10 comments · Fixed by #1023
Closed

std::time::Instant not supported by WebAssembly #1022

niklaskorz opened this issue Jan 1, 2022 · 10 comments · Fixed by #1023

Comments

@niklaskorz
Copy link
Contributor

The std::time::Instant type used in the egui-winit crate is not supported when running through WebAssembly:

panicked at 'time not implemented on this platform', library/std/src/sys/wasm/../unsupported/time.rs:13:9

WebAssembly could potentially be supported in egui-winit by using a crate such as https://github.com/sebcrozet/instant instead, which only re-exports the std::time::Instant type on native but implements a polyfill for WebAssembly targets.

@niklaskorz
Copy link
Contributor Author

niklaskorz commented Jan 1, 2022

The same crate is already used by winit when the wasm-bindgen feature is enabled by default: https://github.com/rust-windowing/winit/blob/master/Cargo.toml#L26

In other words, this does not really add a dependency as this is already being pulled in by winit itself as a non-optional dependency.

@emilk
Copy link
Owner

emilk commented Jan 3, 2022

Thanks for the PR!

I have never tried winit on the web, so I'm curious how well egui-winit work for you, and how it compares to egui_web. Do you have a link to your project? What are you using to render egui?

@niklaskorz
Copy link
Contributor Author

niklaskorz commented Jan 3, 2022

I'm using wgpu for rendering, Unfortunately, my project requires compute shaders, so it won't work with wgpu's WebGL 2 backend and requires real WebGPU support by the browser. Note that due to some recent changes in WGSL, the application partially works in the latest Firefox Nightly right now but not in Chrome Canary. Hopefully, it will fully work again in a month or two when the browsers are updated. But on latest Firefox Nightly, you should see egui working using the commits from the pull request and the demo link below.

@niklaskorz
Copy link
Contributor Author

niklaskorz commented Jan 3, 2022

grafik

The view on the right does not render in Firefox right now unfortunately, due to the shaders using else if which is required by latest wgpu, but Firefox using an older version that only supports elseif in WGSL.

@niklaskorz
Copy link
Contributor Author

egui itself is rendered by https://github.com/hasenbanck/egui_wgpu_backend which I used in combination with https://github.com/hasenbanck/egui_winit_platform before but now migrated to egui-winit.

@emilk
Copy link
Owner

emilk commented Jan 3, 2022

Very cool, thanks for sharing!

There seems to be some problems with input though, e.g. holding down modifiers and moving the cursor in the text edit field doesn't work as expected. Perhaps a limitation of running winit on the web?

@niklaskorz
Copy link
Contributor Author

Hm which modifiers and OS? I can hold down alt, ctrl or shift on Windows and move the cursor using arrow keys just fine. Note that leaving the text field (losing focus) currently freezes the application because of said shader that uses the new else if syntax. The same applies to most other control elements and will be fixed automatically when the wgpu version in Firefox Nightly is updated.

@emilk
Copy link
Owner

emilk commented Jan 3, 2022

I'm running firefox nightly on my macbook, and holding down alt,shift or cmd and pressing the arrow keys still only moves the cursor by a single character. Holding down ctrl makes the cursor not move at all. cmd-A does not select the text. In short, it seems like all modifier keys are non-working.

@niklaskorz
Copy link
Contributor Author

Ah I misread the "doesn't work as expected" as just "doesn't work". :) Yeah I can reproduce that. 🤔

@niklaskorz
Copy link
Contributor Author

niklaskorz commented Jan 3, 2022

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants