Skip to content
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

Uncaught RuntimeError: unreachable after canvas.requestPointerLock on web platform #2113

Closed
igor-petruk opened this issue Dec 27, 2021 · 1 comment
Labels
DS - web F - wontfix This will not be worked on

Comments

@igor-petruk
Copy link

igor-petruk commented Dec 27, 2021

Hi everyone,

I initiated my window using with_canvas and then in the event loop I do.

if self.is_locked() {
            return false;
}
match event {
            Event::WindowEvent { event, .. } => match event {
                WindowEvent::MouseInput { state, button, .. }
                    if *state == ElementState::Pressed && *button == MouseButton::Left =>
                {
                    info!("CLICK!!!!");
                    let document = web_sys::window().unwrap().document().unwrap();
                    use wasm_bindgen::JsCast;
                    let canvas = document
                        .get_element_by_id("canvas")
                        .unwrap()
                        .dyn_into::<web_sys::HtmlCanvasElement>()
                        .unwrap();
                    canvas.request_pointer_lock();
                    return true;
                }
                _ => {}
            },
            _ => {}
        }

This work and the pointer is locked. Movement events are also processed correctly. The self.is_locked()starts returning true at the beginning of my code snippet because I set as a result of pointerlockchange event.

Then when I do a second click after this I get:

c311d3c……odule.wasm:0x137d08 Uncaught RuntimeError: unreachable
    at __rust_start_panic (c311d3c……odule.wasm:0x137d08)
    at rust_panic (c311d3c……odule.wasm:0x13374a)
    at std::panicking::rust_panic_with_hook::he9bfe03219d715ba (c311d3c….module.wasm:0xb40ad)
    at std::panicking::begin_panic_handler::{{closure}}::h3e6db7c674e79203 (c311d3c….module.wasm:0xda204)
    at std::sys_common::backtrace::__rust_end_short_backtrace::hf31049169beda171 (c311d3c……odule.wasm:0x130e10)
    at rust_begin_unwind (c311d3c……odule.wasm:0x128a11)
    at core::panicking::panic_fmt::hbf21a3d4bbb82bf8 (c311d3c……odule.wasm:0x130e46)
    at core::result::unwrap_failed::h27f43d993c3864a1 (c311d3c….module.wasm:0xe58c7)
    at core::result::Result<T,E>::expect::h2d37343035827684 (c311d3c….module.wasm:0xdd563)
    at winit::platform_impl::platform::backend::canvas::pointer_handler::PointerHandler::on_mouse_press::{{closure}}::hcdd5ca9c2244ccf0 (c311d3c….module.wasm:0x659d7)
$__rust_start_panic	@	c311d3c……odule.wasm:0x137d08
$rust_panic	@	c311d3c……odule.wasm:0x13374a
$std::panicking::rust_panic_with_hook::he9bfe03219d715ba	@	c311d3c….module.wasm:0xb40ad
$std::panicking::begin_panic_handler::{{closure}}::h3e6db7c674e79203	@	c311d3c….module.wasm:0xda204
$std::sys_common::backtrace::__rust_end_short_backtrace::hf31049169beda171	@	c311d3c……odule.wasm:0x130e10
$rust_begin_unwind	@	c311d3c……odule.wasm:0x128a11
$core::panicking::panic_fmt::hbf21a3d4bbb82bf8	@	c311d3c……odule.wasm:0x130e46
$core::result::unwrap_failed::h27f43d993c3864a1	@	c311d3c….module.wasm:0xe58c7
$core::result::Result<T,E>::expect::h2d37343035827684	@	c311d3c….module.wasm:0xdd563
$winit::platform_impl::platform::backend::canvas::pointer_handler::PointerHandler::on_mouse_press::{{closure}}::hcdd5ca9c2244ccf0	@	c311d3c….module.wasm:0x659d7
$winit::platform_impl::platform::backend::canvas::Common::add_user_event::{{closure}}::hab8a4764f0a06076	@	c311d3c….module.wasm:0x678c8
$winit::platform_impl::platform::backend::canvas::Common::add_event::{{closure}}::h2c3915f606eb83d0	@	c311d3c….module.wasm:0xef7f4
$<dyn core::ops::function::FnMut<(A,)>+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::h71b4812c36914dbe	@	c311d3c….module.wasm:0xbbd8a
__wbg_adapter_35	@	app_bg.js:445
real

This happens inside of the framework. What is interesting, if I log input, I still get the events through, even if before event processing I've got this crash.

This happens in the context of the WebGPU application, which quickly fails to render with strange errors like:

Command buffer recording ended before [RenderPassEncoder] was ended.
    at Finish (..<URL>)
    at FinishInternal (..<URL>)

250[Invalid CommandBuffer] is invalid.
    at ValidateObject (..<URL>)
    at ValidateSubmit (..<URL>)

It is not quite clear how failure during input processing can break WebGPU. If I completely comment out all WebGPU code from the event_loop.run callback, I still get RuntimeError. So it is not WebGPU causing the error, but opposite: the error strangely breaks rendering.

I know it is hard to fully troubleshoot the issue, but before I completely rework the app to provide a minimal example, maybe you have some quick ideas about that particular expect:

    at core::result::Result<T,E>::expect::h2d37343035827684 (c311d3c….module.wasm:0xdd563)
    at winit::platform_impl::platform::backend::canvas::pointer_handler::PointerHandler::on_mouse_press::

I see set_pointer_capture(event.pointer_id()) there, which looks like there is some code related to pointer capture, but still set_cursor_grab is unimlemented on the Web platform.

What could be wrong here?

@maroider maroider added DS - web F - wontfix This will not be worked on labels Dec 27, 2021
@maroider
Copy link
Member

maroider commented Dec 27, 2021

I have a vague idea of what's going on, but we're already working on getting set_cursor_grab working on the web,

#2025 seems to work fine for those who have tested it, but there are a couple of minor issues blocking it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DS - web F - wontfix This will not be worked on
Development

No branches or pull requests

2 participants