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.
This commit is contained in:
Felix Rieseberg
2026-04-13 10:18:41 -07:00
committed by GitHub
parent 35c82c5d09
commit 731a9b2369

View File

@@ -482,17 +482,16 @@ export class Emulator extends React.Component<{}, EmulatorState> {
ipcRenderer.send(IPC_COMMANDS.MACHINE_STARTED); ipcRenderer.send(IPC_COMMANDS.MACHINE_STARTED);
// Restore state. We can't do this right away // Wait for v86 to finish loading wasm/bios/hda before restoring — calling
// and randomly chose 500ms as the appropriate // restore_state on an uninitialized cpu throws and we'd silently cold-boot.
// wait time (lol) window["emulator"].add_listener("emulator-loaded", async () => {
setTimeout(async () => {
if (!this.state.isBootingFresh) { if (!this.state.isBootingFresh) {
await this.restoreState(); await this.restoreState();
} }
this.state.emulator.run(); window["emulator"].run();
this.state.emulator.screen_set_scale(this.state.scale); window["emulator"].screen_set_scale(this.state.scale);
}, 500); });
} }
/** /**