Skip to content

Commit

Permalink
Merge pull request #93 from Snapchat/bkotsopoulossc-patch-1
Browse files Browse the repository at this point in the history
Wasm: Don't hold onto the heap views as a static var
  • Loading branch information
li-feng-sc authored Jul 8, 2022
2 parents c51c118 + 25c58da commit 14c8aef
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions support-lib/wasm/djinni_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,13 @@ em::val getCppProxyClass() {
}

em::val getWasmMemoryBuffer() {
static auto memoryBuffer = em::val::module_property("HEAPU32")["buffer"];
return memoryBuffer;
// When ALLOW_MEMORY_GROWTH is turned on, the WebAssembly.Memory object's underlying buffer changes as it grows,
// and the HEAP* views in the Emscripten module object get reset to new views over the bigger memory buffer.
// In this mode, capturing the heap here as a static variable is incorrect, and leads to runtime errors.
// https://github.com/emscripten-core/emscripten/blob/3.1.7/src/settings.js#L194-L207 is the growth setting
// https://github.com/emscripten-core/emscripten/blob/3.1.7/src/library.js#L127 is the call to reset the views after grow()
// https://github.com/emscripten-core/emscripten/blob/3.1.7/src/preamble.js#L269-L286 is where the views get reset
return em::val::module_property("HEAPU32")["buffer"];
}

em::val DataObject::createJsObject() {
Expand Down

0 comments on commit 14c8aef

Please sign in to comment.