bevy_framepace icon indicating copy to clipboard operation
bevy_framepace copied to clipboard

wasm support

Open Aidan-Chelig opened this issue 4 years ago • 4 comments

I noticed this plugin doesn't work when compiled to wasm. This is because std::instant isn't supported on wasm aswell as the spin_sleep library. I was wondering if its possible to have a different method of frame pacing when compiling for web that doesn't use the spin_sleep library. so far replacing std::instant with the instant crate gets us part way there.

Aidan-Chelig avatar Feb 21 '22 07:02 Aidan-Chelig

Spin sleep is critical, as the plugin won't work without precise sleep timing. The first step might be forking or PR'ing spin sleep upstream.

aevyrie avatar Feb 21 '22 19:02 aevyrie

Looks like the issue is Instant::now(), which is not supported on WASM. This could be fixed by using https://github.com/sebcrozet/instant as a polyfill in spin_sleep and this library.

aevyrie avatar Aug 11 '22 17:08 aevyrie

Reopening - Instant::now() still needs to be removed for wasm support. Spin sleep has been removed though.

aevyrie avatar Aug 26 '22 01:08 aevyrie

Hm, actually we are switched over to bevy's built-in Instant::now() which should mean this is actually working on wasm, need to test first.

aevyrie avatar Aug 26 '22 01:08 aevyrie

I attempted to use Framepace in my WASM build and it results in this error:

bevy_winit-0.8.1\src\winit_windows.rs:265:19

Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f.js:417:21)
    at console_error_panic_hook::Error::new::h57413bb8b3805c00 (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[143326]:0x2933c31)
    at console_error_panic_hook::hook_impl::hdc1902448d002c5b (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[19053]:0x17c7ce2)
    at console_error_panic_hook::hook::hd963d54b60ab1d89 (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[159176]:0x2a0efb2)
    at core::ops::function::Fn::call::he4c4b44ff8004736 (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[134468]:0x28a8942)
    at std::panicking::rust_panic_with_hook::hb09154fa23e06c37 (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[46951]:0x1f6019a)
    at std::panicking::begin_panic_handler::{{closure}}::h6091c197f0d08bf0 (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[63329]:0x220f9af)
    at std::sys_common::backtrace::__rust_end_short_backtrace::h004afb3e6a867c40 (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[183100]:0x2af64ea)
    at rust_begin_unwind (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[150081]:0x2994cbd)
    at core::panicking::panic_fmt::h9e229748e3ae9f9d (http://127.0.0.1:8080/bevy_test-63b38fe71961e48f_bg.wasm:wasm-function[153723]:0x29c632e)

InfernoStats avatar Oct 29 '22 06:10 InfernoStats