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

fails to load when built to WASM #11

Closed
jaminhaber opened this issue Dec 10, 2023 · 7 comments
Closed

fails to load when built to WASM #11

jaminhaber opened this issue Dec 10, 2023 · 7 comments

Comments

@jaminhaber
Copy link

I have a bevy project with the story added as a NonSend resource but I am encountering the following error when exporting as WASM and embedding on a web page.

The error may or may not be related to this package but just wanted to flag it

Main fn:

let story = Story::new(include_str!("./story/story.json")).unwrap();
let mut app = App::new();
app.insert_non_send_resource(story);

Error:

Uncaught (in promise) RuntimeError: unreachable
    at __rust_start_panic (game_bg.e0ece47b.wasm:0x171f90e)
    at rust_panic (game_bg.e0ece47b.wasm:0x1711605)
    at std::panicking::rust_panic_with_hook::hbf46ef0245cc9589 (game_bg.e0ece47b.wasm:0x14847aa)
    at std::panicking::begin_panic_handler::{{closure}}::hc07db454214d2c87 (game_bg.e0ece47b.wasm:0x1521f4e)
    at std::sys_common::backtrace::__rust_end_short_backtrace::hf9e2f055fb5ef672 (game_bg.e0ece47b.wasm:0x171c477)
    at rust_begin_unwind (game_bg.e0ece47b.wasm:0x161d76d)
    at core::panicking::panic_fmt::h14c85a61aa3d538e (game_bg.e0ece47b.wasm:0x167406c)
    at std::time::Instant::now::he2d8cf30b81330fa (game_bg.e0ece47b.wasm:0x1673f23)
    at bladeink::story::progress::<impl bladeink::story::Story>::continue_internal::he05d60203bd9bce5 (game_bg.e0ece47b.wasm:0x19c58a)
    at bladeink::story::state::<impl bladeink::story::Story>::reset_globals::h272fc682d3f4ee58 (game_bg.e0ece47b.wasm:0xf3e9bf)
    at bladeink::story::misc::<impl bladeink::story::Story>::new::h5d9d13532e11e82e (game_bg.e0ece47b.wasm:0x650187)
    at los_angeles_simulator::main::h1f457f74b5faf998 (game_bg.e0ece47b.wasm:0x3be4b7)
    at std::sys_common::backtrace::__rust_begin_short_backtrace::h3e02078434879a59 (game_bg.e0ece47b.wasm:0x171c4b5)
    at std::rt::lang_start::{{closure}}::hf46eb1497fcb98e8 (game_bg.e0ece47b.wasm:0x168d364)
    at std::rt::lang_start_internal::h20a8087e5817ee7c (game_bg.e0ece47b.wasm:0x1395d21)
    at main (game_bg.e0ece47b.wasm:0x1686c65)
    at game_bg.e0ece47b.wasm:0x1711713
    at __wbg_finalize_init (game.js:1901:10)
    at Module.__wbg_init [as default] (game.js:1937:12)
    at async runWasm (game.tsx:13:7)
@jaminhaber jaminhaber changed the title fails to load when built to WASM fails to load when built to WASM with bevy Dec 10, 2023
@jaminhaber
Copy link
Author

jaminhaber commented Dec 10, 2023

Seems to be coming from this line which seems to be a known issue with Instant::now when compiling for wasm32-unknown-unknown. Is it possible to disable some of the features behind a "no-std" or "wasm" flag?

@jaminhaber
Copy link
Author

I can confirm it works with my fork here where i simply delete that code - I can use that for now since I am not taking advantage of any async code 👍🏻 If you want I can look about adding a flag for async stuff?

@IFcoltransG
Copy link
Contributor

That code should only need to run Instant::now if the is_async_time_limited value is true. Maybe it should be an Option<Instant>, set to None if is_async_time_limited is false, and its contents could be checked instead of this condition.

@IFcoltransG
Copy link
Contributor

(As a bigger refactor, I was thinking this code could be made into more of a co-routine pattern, meaning the code related to time and milliseconds could be abstracted out. The timing aspect is just a function that says "keep going" or "stop", and it feels weird to have this core function dealing directly in milliseconds.)

@jaminhaber jaminhaber changed the title fails to load when built to WASM with bevy fails to load when built to WASM Dec 25, 2023
@bladecoder
Copy link
Owner

I think that this PR should fix this issue and enables the use of async feature in WASM too: #12

I could not test it. @jaminhaber , could you test it before I merge?

@IFcoltransG, what do you think about this solution?

@jaminhaber
Copy link
Author

jaminhaber commented Jan 2, 2024

Yep! I am able to run the game in wasm with this:

bladeink = { git = "https://github.com/bladecoder/blade-ink-rs", branch = "fix/wasm_instant_now" }

@bladecoder
Copy link
Owner

Branch merged in master.

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

No branches or pull requests

3 participants