Webasm: null pointer passed to rust

I am migrating a legacy JS code to Rust+WebAssembly, replace one part at a time and running the original tests (that use QUnit). The code is rather large, so I cannot post it, and I was not able to make a

I am getting a strange bug with some structs. Briefly, everything works in the browser until I get an error out of the blue "null pointer passed to rust". (All methods use &self, the struct only contains some f64 inside)

It seems that it happens when a container holding a "Rust object" is deleted, as if something is not being deallocated in the right order. I am having a hard time chasing this bug. Any idea how to approach this bug or what the source might be?

A quick follow up. There is an instance of a Rust object inside a JS object. A function that is periodically called using a timer calls a method of the JS object which in turn tries to access a property of the rust object. Everything works until that part of the program finishes, objects gets destroyed, ptr becomes 0 for the rust object and I get a null pointer passed to rust. Importantly, this does not happen when the original pure JS object is used.

It seems that things are getting GC in the wrong order.

If you haven't tried it already, logging via console.log in several places (the timer, a Drop implementation for the Rust struct, etc.) might help determine exactly when the struct is being destroyed.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.