a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit a112d920bd70eca35f43501c766a4555e7136c74
parent 64a46e1ed61f9fb674ff5c1e7346d17c42cb0f5d
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Tue, 16 Jul 2019 20:27:39 -0700

Handle JS file loading failure

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; }