a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit e67d48fdde773652152e26a035161da7fb2469fa
parent 37f0619d402427a277fb78632dfb26c0546cfb3f
Author: amin <dev@aminmesbah.com>
Date:   Wed, 17 Jul 2019 03:27:39 +0000

Handle JS file loading failure

FossilOrigin-Name: 09cdd142c5e1de3be9fcf4b312505f03823e9c4baa7af4b598fbd48ba349da14
Diffstat:
Msrc/platform_wasm.c | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/platform_wasm.c b/src/platform_wasm.c @@ -128,11 +128,21 @@ PLATFORM_READ_ENTIRE_FILE(wasm_read_entire_file) *out_num_bytes = num_bytes_in_file; } + size_t fail_reversion_marker = mem_st_get_marker(a); u8 *buf = mem_st_alloc_buffer(a, u8, num_bytes_in_file + 1); assert(buf); - js_read_entire_file((i32)file_path, str_length(file_path), buf); - buf[num_bytes_in_file] = '\0'; - wasm_print("Succeeded in reading file."); + bool success = js_read_entire_file((i32)file_path, str_length(file_path), buf); + if (success) + { + buf[num_bytes_in_file] = '\0'; + wasm_print("Succeeded in reading file."); + } + else + { + mem_st_free_to_marker(a, fail_reversion_marker); + buf = NULL; + wasm_print("Failed to read file."); + } return buf; }