diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2023-04-02 20:58:30 +0100 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2023-04-02 21:17:11 +0100 |
| commit | 8d3a93ce47237114a88d8bed81ab175994eb9a6b (patch) | |
| tree | 11cc8a73420a072748e5acb3242c3539e1e1992f /emccpre.js | |
| parent | 2499eb47fa4e0c86bc1b6100b4922026670b2ad8 (diff) | |
| download | puzzles-8d3a93ce47237114a88d8bed81ab175994eb9a6b.zip puzzles-8d3a93ce47237114a88d8bed81ab175994eb9a6b.tar.gz puzzles-8d3a93ce47237114a88d8bed81ab175994eb9a6b.tar.bz2 puzzles-8d3a93ce47237114a88d8bed81ab175994eb9a6b.tar.xz | |
js: load games using FileReader.readAsArrayBuffer()
Using .readAsText() meant that trying to load a non-text file (for
instance something that's not a save file at all) would generate an
"RuntimeError: index out of bounds". This would then leave the
Emscripten runtime in a broken state.
It might even be possible for a real save file not to be valid UTF-8,
for instance if it came from a platform that used a different character
encoding for random seeds.
There's still a problem with opening very large files, apparently
because Emscripten tries to stuff the entire file onto the C stack.
That will probably have to be fixed by properly exposing the incremental
file-loading API to JavaScript.
Diffstat (limited to 'emccpre.js')
| -rw-r--r-- | emccpre.js | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -423,7 +423,7 @@ function initPuzzle() { // 'number' is used for C pointers var get_save_file = Module.cwrap('get_save_file', 'number', []); var free_save_file = Module.cwrap('free_save_file', 'void', ['number']); - var load_game = Module.cwrap('load_game', 'void', ['string', 'number']); + var load_game = Module.cwrap('load_game', 'void', ['array', 'number']); if (save_button) save_button.onclick = function(event) { if (dlg_dimmer === null) { @@ -457,10 +457,10 @@ function initPuzzle() { var file = input.files.item(0); var reader = new FileReader(); reader.addEventListener("loadend", function() { - var string = reader.result; - load_game(string, string.length); + var array = new Uint8Array(reader.result); + load_game(array, array.length); }); - reader.readAsText(file); + reader.readAsArrayBuffer(file); } }); input.click(); |