fix(developer): kmcmplib was clobbering previous output
Running kmc on a set of keyboards would sporadically fail after some time. It turns out this was related to memory allocation, specifically, resizing the WASM module's memory buffer caused `TypedArray` views into the memory to be reset! By default, when a `Uint8Array` is created from an `ArrayBuffer` (e.g. `Module.HEAP8.buffer`), it is a dynamic view into that buffer. This module buffer can be dynamically reallocated at any time, which can happen when allocating memory in WASM code (so the change will look _really_ weird in a stack trace). Thus, to ensure we don't trip over ourselves, we need to copy the buffer. Fortunately, creating a `Uint8Array` from a `Uint8Array` copies the data, and is pretty quick.
parent
56da6479
Please register or sign in to comment