I am currently building a small project that outsources it's processing into wasm compiled from rust. I am using wasm-bindgen, wasm-pack and webpack. Shortly after the WASM is instantiated, I get the error described above. When looking at the wat format, it tries to access memory f32.store offset=9331392
at ~9mb into the buffer. When I inserted console.log(wasm.memory.buffer.byteLength)
into the glue code, it says that only 4mb is available. Does anyone know how I can either:
- make the memory grow dynamically
- set an initial memory size
Help would very much be appreciated. This is my first time using rust/wasm and I don't know how to increase the memory size here.
Edit:
Source code
lib.rs
use wasm_bindgen::{prelude::*, Clamped, JsCast};
use web_sys::ImageData;
extern crate wee_alloc;
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[allow(dead_code)]
fn main() {
#[wasm_bindgen]
pub struct Simulation {
...
}
#[wasm_bindgen]
impl Simulation {
#[wasm_bindgen(constructor)]
pub fn new() -> Result<Simulation, JsValue> {
...
}
fn render(...) -> Result<(), JsValue> {
...
}
}
}