That could work in theory - but the JS state is a big problem, as you said. If anything in JS closes over state, or otherwise creates data you can't serialize, it won't work. Emscripten does save some state in JS, some obvious examples are the things you said you are not using (like FS). But if you use the WebGL support for example then you also have a bunch of JS objects (like WebGL buffers) that represent browser state that can't be serialized.
The wasm part is much simpler, but aside from the wasm memory which is easy to serialize, you also need to save the globals (like the stack pointer). Those aren't externally visible or modifiable, so you'd need to add methods to save and load them. On Fri, May 10, 2019 at 4:33 AM Александр Гурьянов <[email protected]> wrote: > Hi is it possible to make snapshot of runtime, serelize it to file and > then restore runtime on other client. I understand that snapshotting > have a lot of pitfalls. But for now I want to implement simpliest > case. My target is wasm, main loop is executed by requestAnimation > frame. > > So stack always same: > > request animation frame -> loop function -> create/resotre memory -> > actual programm implementation > > The first code in loop function is to restore/save heap, like this: > > static void em_main_loop(void) { > if (doHeapOperation()) { > return; > } > > // actual programm implementation > } > > As heapOperation I use this: > > Module.heapOperation = function() { > delete Module.heapOperation; > var buffer = new ArrayBuffer(Module.HEAPU8.byteLength); > window.heapCopy = new Uint8Array(buffer); > window.heapCopy.set(Module.HEAPU8); > console.log("INFO: heapCopy created"); > > function restore() { > Module.heapOperation = function() { > delete Module.heapOperation; > Module.HEAPU8.set(window.heapCopy); > console.log("INFO: heapCopy loaded"); > } > }; > > setTimeout(restore, 1000); > } > > So, I just saving all wasm memory, and then restore it after 1 sec. > And this code works in 50% cases, sometimes program is start as 1 > second before, but other time it continue with unpredictable > behaviour. > > Because we paused / resume with same memory and same stack I assume > that everything should works. But, in reality it does not. Is > emscripten also save some state in javascript? What I am missing. > Assume that my program did not use FS, GPU, SOUNDS and pure native (no > EM_ASM inside), is this technique should works? > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/emscripten-discuss/CAKOm%3DVHBPUGg7%3DbWSTT0b_%2BKy5TAv6LvHk2Kc7Un3udY6%2BGTLQ%40mail.gmail.com > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpRh-x-xbSRbhx4ksvXpLd9vh%3Dr%3Dtzbrg--9m-1ugY3-4Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
