1

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> {
            ...
        }
    }
}

leonhma
  • 110
  • 9
  • Which allocator are you using? I think wee_alloc is considered deprecated despite being recommend in the docs – BallpointBen Sep 23 '22 at 16:19
  • As I said, this is my first time using rust with wasm, so I am basically just copying examples and modifying them to my needs. I have added wee_alloc to my code, but the same thing is still happening. I am gonna add some code to my question, maybe this helps. – leonhma Sep 24 '22 at 13:25
  • got it once and then it disappeared without any traces :/ – user656449 Dec 05 '22 at 09:45

0 Answers0