Skip to content

Commit e3caa27

Browse files
authored
Skip loadExtRam when the buffer is empty (#74)
An empty Uint8Array is still truthy, so the constructor's `if (extRamBuffer)` guard called loadExtRam even when there was no save data to restore. For carts that don't advertise external RAM (MBC5 with EXT_RAM_SIZE_NONE, ROM-only, etc.), `_ext_ram_file_data_new` returns 0 and the wasm side then reads from a null file-data ptr inside `_emulator_read_ext_ram`. Sometimes that lands on valid wasm linear memory, sometimes it's out of bounds depending on heap state from prior alloc/free cycles — surfacing as an intermittent "RuntimeError: memory access out of bounds" in long-running embed scenarios that recreate the Emulator multiple times. Tighten the guard to also require `extRamBuffer.byteLength > 0`.
1 parent b5f718e commit e3caa27

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

docs/simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Emulator {
177177
this.fps = 60;
178178
this.fastForward = false;
179179

180-
if (extRamBuffer) {
180+
if (extRamBuffer && extRamBuffer.byteLength > 0) {
181181
this.loadExtRam(extRamBuffer);
182182
}
183183

0 commit comments

Comments
 (0)