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

Mark functions incompatible with SharedArrayBuffer and provide alternative signatures #3772

Closed
kettle11 opened this issue Jan 9, 2024 · 1 comment · Fixed by #4156
Closed

Comments

@kettle11
Copy link

kettle11 commented Jan 9, 2024

Presently browser's will crash if copyToChannel(source, channelNumber) is called with a Float32Array that is backed by a SharedArrayBuffer. I opened an issue on that here: WebAudio/web-audio-api#2565

While the browser's copyToChannel function accepts a Float32Array as the source argument web-sys instead takes in a &[f32]. This is likely for convenience but it also makes it impossible to use web_sys's copy_to_channel in cases where the Float32Array was acquired from a source that's not the Wasm instance's memory. This seems like an API oversight to me.

This limitation means that if the memory is backed by a SharedArrayBuffer copy_to_channel simply cannot be used without causing a crash.

That makes workarounds, like the one required for this issue: RustAudio/cpal#656, a little messier.

Workarounds are possible but it also seems like the web_sys API should consider changing.

@daxpedda
Copy link
Collaborator

Agreed, probably all methods which take a view should probably also generate a function which takes an appropriate array buffer. I think it would be nice to figure out a way to pass both at the same time (e.g. with a trait), but that would be a breaking change.
Additionally, to fix the current behavior, it might be good to guard this method behind a cfg(not(target_feature = "atomics")).

Happy to review a PR!

@daxpedda daxpedda changed the title web_sys::AudioBuffer::copy_to_channel cannot be called when Wasm memory is backed by SharedArrayBuffer Mark functions incompatible with SharedArrayBuffer and provide alternative signatures Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants