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

Library crashes when compiled to WASM with atomics flag enabled #10

Closed
drewhk opened this issue Sep 12, 2024 · 5 comments
Closed

Library crashes when compiled to WASM with atomics flag enabled #10

drewhk opened this issue Sep 12, 2024 · 5 comments

Comments

@drewhk
Copy link

drewhk commented Sep 12, 2024

When compiled to WASM with atomics flag (which flutter rust bridge enables) the library crashes due to

.cargo\registry\src\index.crates.io-6f17d22bba15001f\tinyaudio-0.1.4\src\web.rs:57:14:
called `Result::unwrap()` on an `Err` value: JsValue(TypeError: Failed to execute 'copyToChannel' on 'AudioBuffer': The provided Float32Array value must not be shared.
TypeError: Failed to execute 'copyToChannel' on 'AudioBuffer': The provided Float32Array value must not be shared.

This error is exactly the same as documented in cpal: RustAudio/cpal#656
Fixed here: https://github.com/RustAudio/cpal/pull/837/files

Basically with this flag the generated WASM code uses SharedArrayBuffer, but the copyToChannel only allows Float32Array.
See also the related ticket on wasm-bindgen: rustwasm/wasm-bindgen#3772

@mrDIMAS
Copy link
Owner

mrDIMAS commented Sep 12, 2024

Could you please try the fix? I checked it with the following commands and it seems to work fine

cd wasm-examples
rustup default nightly
RUSTFLAGS="-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals" wasm-pack build . --target=web -- -Z build-std=panic_abort,std
basic-http-server

@drewhk
Copy link
Author

drewhk commented Sep 12, 2024

Works perfectly, thank you for the very quick fix, much appreciated!

@mrDIMAS
Copy link
Owner

mrDIMAS commented Sep 12, 2024

Cool, I'll submit a new version on crates.io then.

@mrDIMAS
Copy link
Owner

mrDIMAS commented Sep 12, 2024

I've published 0.2.0, closing this as completed.

@mrDIMAS mrDIMAS closed this as completed Sep 12, 2024
@drewhk
Copy link
Author

drewhk commented Sep 12, 2024

Many thanks! I owe you a beverage :D

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

2 participants