-
Notifications
You must be signed in to change notification settings - Fork 239
Closed
Description
I'm building a project (bevy) on multithreaded wasm via web workers and this library crashes with exception:
Uncaught (in promise) TypeError: Failed to execute 'getRandomValues' on 'Crypto': The provided ArrayBufferView value must not be shared.
Indeed the spec does not allow generating random numbers into a memory backed by SharedArrayBuffer.
I managed to fix this issue by generating numbers into an intermediate buffer allocated by javascript:
for chunk in dest.chunks_mut(65536) {
let arr = js_sys::Uint8Array::new_with_length(chunk.len() as u32);
n.get_random_values(&arr);
arr.copy_to(chunk);
}
This introduces some overhead, but I'm not sure if there is a standard way to check whether rust's memory is backed by SharedArrayBuffer.
I can submit a PR for this, so let me know how you want me to proceed.
Metadata
Metadata
Assignees
Labels
No labels