From 51b4a3fc75351d6ecd2142c228d31a1f7ed52152 Mon Sep 17 00:00:00 2001 From: Omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sun, 17 Mar 2024 15:00:53 +1100 Subject: fix a bug with dirname seg faulting when passed a string literal it doesnt like things in readonly memory i guess. now we create an arena for the obj load and create a dynamically allocated copy of the string --- src/resources/obj.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/resources/obj.c') diff --git a/src/resources/obj.c b/src/resources/obj.c index 56f885f..c6e9fa6 100644 --- a/src/resources/obj.c +++ b/src/resources/obj.c @@ -15,6 +15,7 @@ #include "file.h" #include "log.h" #include "maths.h" +#include "mem.h" #include "path.h" #include "render.h" #include "render_types.h" @@ -40,8 +41,11 @@ bool model_load_obj_str(const char *file_string, str8 relative_path, model *out_ bool invert_textures_y); model_handle model_load_obj(core *core, const char *path, bool invert_textures_y) { + size_t arena_size = 1024; + arena scratch = arena_create(malloc(arena_size), arena_size); + TRACE("Loading model at Path %s\n", path); - path_opt relative_path = path_parent(path); + path_opt relative_path = path_parent(&scratch, path); if (!relative_path.has_value) { WARN("Couldnt get a relative path for the path to use for loading materials & textures later"); } @@ -61,6 +65,9 @@ model_handle model_load_obj(core *core, const char *path, bool invert_textures_y u32 index = model_darray_len(core->models); model_darray_push(core->models, model); + + arena_free_all(&scratch); + arena_free_storage(&scratch); return (model_handle){ .raw = index }; } -- cgit v1.2.3-70-g09d2