You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with passing strings between Rust and JavaScript on the wasm32-unknown-unknown target, but I'm consistently getting memory access out of bounds panics in Rust. I'm not able to determine if Rust or my code is at fault.
In the browser console there are console logs showing the first Rust function is invoked from JavaScript, which requires an allocation for the input string pointer, and an allocation for the string output pointer—there are JavaScript calls for the input alloc and both the input and output dealloc, if that matters.
There's a console log for the second Rust function invoked by the JavaScript side, and it's somewhere in here that the memory access out of bounds error occurs. Here's the full error message:
Uncaught (in promise) RuntimeError: memory access out of bounds
at wasm-function[78]:192
at wasm-function[1]:79
at toUppercase (webpack:///./src/index.js?:30:42)
at eval (webpack:///./src/index.js?:34:41)
at <anonymous>
This is in release mode. Change release to false in webpack.config.js for a debug build. This time there's no console logs and an error appears immediately:
Uncaught (in promise) RuntimeError: function signature mismatch
at core::fmt::write::hea786a1481adb9e0 (wasm-function[392]:3395)
at core::fmt::Write::write_fmt::h3f7ec2411e6ba1c8 (wasm-function[164]:262)
at std::panicking::begin_panic_fmt::h3fe5ef599a9ea351 (wasm-function[245]:318)
at rust_begin_unwind (wasm-function[244]:86)
at core::panicking::panic_fmt::h1bceab3183b318fb (wasm-function[442]:588)
at core::panicking::panic::he74d65cc02d05038 (wasm-function[440]:207)
at <core::option::Option<T>>::unwrap::h286d6daff2767775 (wasm-function[52]:87)
at <alloc::raw_vec::RawVec<T, A>>::allocate_in::h7e6e3ac111344e5e (wasm-function[19]:372)
at <alloc::raw_vec::RawVec<T>>::with_capacity::h81415bd27391e5af (wasm-function[18]:60)
at <alloc::vec::Vec<T>>::with_capacity::hebebed3340b32776 (wasm-function[28]:54)
at alloc (wasm-function[73]:69)
at Prelude.createString (webpack:////wasm-rust-utils/packages/wasm-rust-utils/dist/wasm-rust-utils.js?:93:24)
at opposite (webpack:///./src/index.js?:19:25)
at eval (webpack:///./src/index.js?:25:42)
at <anonymous>
I'm totally lost as to how to proceed, on the surface it seems that an arbitrary amount of allocations in Rust cause the program to fail in release mode, and there's some other issue in debug mode.
I've figured out all the issues I was running into, which can pretty much all be summed up as calling CString::from_raw without fully understanding the underlying semantics.
The issue with building in debug mode has existed in other reports and seems to be LLVM related.
I'm working with passing strings between Rust and JavaScript on the
wasm32-unknown-unknown
target, but I'm consistently gettingmemory access out of bounds
panics in Rust. I'm not able to determine if Rust or my code is at fault.Here's a simple demonstration of the problem.
A short overview of what's going on in my failing example:
webpack
and the Rust build is invoked byrust-native-wasm-loader
.memory access out of bounds
error occurs. Here's the full error message:release
tofalse
inwebpack.config.js
for a debug build. This time there's no console logs and an error appears immediately:I'm totally lost as to how to proceed, on the surface it seems that an arbitrary amount of allocations in Rust cause the program to fail in release mode, and there's some other issue in debug mode.
Could this be at all related to #46367 ?
The text was updated successfully, but these errors were encountered: