-
Notifications
You must be signed in to change notification settings - Fork 60
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
wasm: enable events loop #459
Conversation
Enabling both fails due to use of moved values, will need to see how to share this state:
|
Errors with this branch, first comes from winit:
https://github.com/rust-windowing/winit/blob/master/src/platform_impl/web/event_loop/mod.rs#L42-L46 // Throw an exception to break out of Rust exceution and use unreachable to tell the
// compiler this function won't return, giving it a return type of '!'
backend::throw(
"Using exceptions for control flow, don't mind me. This isn't actually an error!",
); if not actually an error, why is it logged in the browser console? The screen renders, but if we click on it, then a panic:
src/main.rs:657 is next error doesn't say much:
then this last error, most serious:
when borrowing: render_loop.run(move |running: &mut bool| {
info!("render_loop start");
let winit_window = winit_window.borrow_mut(); meaning the events_loop started (then panicked-NotSupportedError), and then render_loop started and borrowed at the same time. Wasn't expecting both loops to be executing simultaneously — maybe they aren't but this simultaneous borrow_mut() is a consequence of events_loop panicking first? |
winit has/had support for Pointer Lock API through emscripten: rust-windowing/winit@769d4fe but it does not yet through web-sys, there is an open issue: rust-windowing/winit#1674 Pointer Lock is definitely needed. But on this line of code, it is actually trying to disable pointer grab. Commenting it out for testing, mouse events do work — including hover and click: |
…nter Lock is available
This reverts commit 542fa1b.
error[E0716]: temporary value dropped while borrowed --> src/main.rs:332:24 | 332 | let winit_window = Box::leak(Box::new(glutin_window)).borrow().window(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------- temporary value is freed at the end of this statement | | | creates a temporary which is freed while still in use | argument requires that borrow lasts for `'static` error[E0382]: use of moved value: `glutin_window` --> src/main.rs:437:21 | 330 | let glutin_window = RefCell::new(Box::leak(Box::new(glutin_window))); | ------------- move occurs because `glutin_window` has type `RefCell<&mut ContextWrapper<PossiblyCurrent, winit::window::Window>>`, which does not implement the `Copy` trait 331 | #[cfg(not(target_arch = "wasm32"))] 332 | let winit_window = Box::leak(Box::new(glutin_window)).borrow().window(); | ------------- value moved here ... 437 | events_loop.run(move |event, _event_loop, control_flow| { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ value used here after move ... 458 | glutin_window.borrow().resize(physical_size); | ------------- use occurs due to use in closure error: aborting due to 2 previous errors
This reverts commit 8f78ec4.
This works on wasm but breaks native, because of borrowing
|
Web has a separate render loop and window event loop, will need to handle both
#446 🕸️ Web support