I'm having my first play with wasm via Webassembly Studio (so apologies if this bug is in the wrong place - I am taking a punt and assuming that bindgen is the most likely cause!).
I tried creating a struct on the Rust side of things (containing a vector, but I don't think that makes a difference). I wrote a simple "new" method to obtain the struct and called this from the JS side. On trying to then do anything else with the struct on the JS side, I encounter the error
Uncaught (in promise) Error: null pointer passed to rust
My snippet is here:
https://webassembly.studio/?f=4hm9m5losw
I might be doing something really obvious wrong, but offhand I cannot see what! It seems as if the "new" method does not properly instantiate the object, as it is missing a pointer.
To end on a high, thanks for the great work; this rust->wasm stuff is amazing!
Thanks for the report! The issue here is using new Hello() instead of Hello.new(). In wasm-bindgen's debug mode this'll throw an error about doing this at runtime, but in release mode (which the webassembly.studio site is using by default) these checks are omitted.
You should also be able to add #[wasm_bindgen(constructor)] to the new method and have new Hello() work!
Does that work well enough for now?
Thanks for the explanation; both of those suggestions work as expected!
Most helpful comment
Thanks for the report! The issue here is using
new Hello()instead ofHello.new(). In wasm-bindgen's debug mode this'll throw an error about doing this at runtime, but in release mode (which the webassembly.studio site is using by default) these checks are omitted.You should also be able to add
#[wasm_bindgen(constructor)]to thenewmethod and havenew Hello()work!Does that work well enough for now?