From 731a9b236980211efd7d6972e27659012f44dd3a Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Mon, 13 Apr 2026 10:18:41 -0700 Subject: [PATCH] Wait for v86 emulator-loaded before restoring state (#367) The 500ms setTimeout raced against v86's async wasm/BIOS/hda load. When loading exceeded 500ms (cold cache, Gatekeeper scan on packaged apps), restore_state ran on an uninitialized CPU, threw, was silently caught, and the VM cold-booted from default-state.bin instead of resuming the user's session. --- src/renderer/emulator.tsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/renderer/emulator.tsx b/src/renderer/emulator.tsx index de5e338..d7a5480 100644 --- a/src/renderer/emulator.tsx +++ b/src/renderer/emulator.tsx @@ -482,17 +482,16 @@ export class Emulator extends React.Component<{}, EmulatorState> { ipcRenderer.send(IPC_COMMANDS.MACHINE_STARTED); - // Restore state. We can't do this right away - // and randomly chose 500ms as the appropriate - // wait time (lol) - setTimeout(async () => { + // Wait for v86 to finish loading wasm/bios/hda before restoring — calling + // restore_state on an uninitialized cpu throws and we'd silently cold-boot. + window["emulator"].add_listener("emulator-loaded", async () => { if (!this.state.isBootingFresh) { await this.restoreState(); } - this.state.emulator.run(); - this.state.emulator.screen_set_scale(this.state.scale); - }, 500); + window["emulator"].run(); + window["emulator"].screen_set_scale(this.state.scale); + }); } /**