-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eagerly cached TypedArray objects cause circular dependency for bundler modes #2961
Labels
Comments
Liamolucko
added a commit
to Liamolucko/wasm-bindgen
that referenced
this issue
Jun 27, 2022
In the bundler target, there's a circular dependency between the bindings and the wasm module. That means that the wasm module's exports aren't available at the top level. In rustwasm#2886, I didn't realise that and made the memory views be initialised at the top level, which resulted in an error from the wasm module's memory not being available yet. This fixes that by lazily initialising the memory views like they were before rustwasm#2886, except that they're reset to uninitialised in `init` to make sure they're updated if it's called multiple times (the reason I made them be immediately initialised in the first place).
ranile
pushed a commit
that referenced
this issue
Jun 27, 2022
In the bundler target, there's a circular dependency between the bindings and the wasm module. That means that the wasm module's exports aren't available at the top level. In #2886, I didn't realise that and made the memory views be initialised at the top level, which resulted in an error from the wasm module's memory not being available yet. This fixes that by lazily initialising the memory views like they were before #2886, except that they're reset to uninitialised in `init` to make sure they're updated if it's called multiple times (the reason I made them be immediately initialised in the first place).
This was referenced Jul 2, 2022
In my case (running in Node.js 16, importing the wasm-bindgen module as an ES module, having run ReferenceError: memory is not defined (just adding that comment to make this issue easier for others to find than it was for me! 😊) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the Bug
Descriptions like
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
creates a circular dependency between thebg
module and the instantiation wrapper created by bundlers, because the wrapper needs to import thebg
module to pass the exports toWebAssembly.instantiate
's second argument (importObject
), while this depends onwasm.memory
which is initialized after the instantiation is complete.Steps to Reproduce
I haven't isolated the reproduction yet, because it seems to depend on the use of certain ArrayBuffer related function calls.
I'm using https://github.com/Menci/vite-plugin-wasm, but at a quick glance Webpack should be doing the implementation in basically the same manner.
Errors
Proposed modification
Just make it lazy.
The text was updated successfully, but these errors were encountered: