simon-git: puzzles (main): Ben Harris
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Mon Apr 3 22:21:45 BST 2023
TL;DR:
36c282a js: Load save files into the C side incrementally
4de5d20 js: use the "load" event for loading save files
Repository: https://git.tartarus.org/simon/puzzles.git
On the web: https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: main
Committer: Ben Harris <bjh21 at bjh21.me.uk>
Date: 2023-04-03 22:21:45
commit 36c282aaa92bd42d570cdc76fe3b9e76d8da1ff1
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=36c282aaa92bd42d570cdc76fe3b9e76d8da1ff1;hp=8d3a93ce47237114a88d8bed81ab175994eb9a6b
Author: Ben Harris <bjh21 at bjh21.me.uk>
Date: Mon Apr 3 15:16:35 2023 +0100
js: Load save files into the C side incrementally
Before this commit, JavaScript Puzzles loaded a save file by pushing the
entire file onto the Emscripten stack and then reading it from there.
This worked tolerably for typical save files, but Emscripten's stack
defaults to only having 64 kiB of space. That meant that trying to load
something that wasn't a real save file tended to cause a stack overflow.
I expect that at least some real save files would suffer from the same
problem.
The stack overflow would generally cause a JavaScript exception and then
leave the stack pointer outside the stack, so that any future attempt to
call into C would fail as well.
To fix this, arrange that the C function for reading data from the save
file calls out to JavaScript. The JavaScript can then copy just the
requested data into the caller's buffer. We can't pass a JavaScript
function pointer to C, but since only one file can be loaded at a time,
we can just have a global variable that's the current loading callback.
There might still be a problem if you try to load a stupendously large
file, since I think FileReader.readAsArrayBuffer() reads the whole file
into the browser's RAM. It works on my laptop with files up to a few
hundred megabytes, though.
emcc.c | 23 ++++++++++-------------
emcclib.js | 9 +++++++++
emccpre.js | 21 ++++++++++++++++++---
3 files changed, 37 insertions(+), 16 deletions(-)
commit 4de5d20368d4b2ca4f0851eafa900cd0c9a3c691
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=4de5d20368d4b2ca4f0851eafa900cd0c9a3c691;hp=36c282aaa92bd42d570cdc76fe3b9e76d8da1ff1
Author: Ben Harris <bjh21 at bjh21.me.uk>
Date: Mon Apr 3 22:11:42 2023 +0100
js: use the "load" event for loading save files
This is in place of the "loadend" event. In Chromium, (and in the
specification), "loadend" is triggered not only when the file is
loaded but also when loading fails. Obviously when loading fails we
don't want to try to parse the (nonexistent) resulting file.
Using the "load" event works better, since it's only fired on success,
and we can also have an "error" handler to report problems with
loading files, albeit with no detail at all.
This doesn't seem to make any difference in Firefox, which in my
testing fires "load" and "loadend" on success and nothing at all on
failure.
emccpre.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
More information about the tartarus-commits
mailing list