diff options
author | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-03-17 15:00:53 +1100 |
---|---|---|
committer | Omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-03-17 15:00:53 +1100 |
commit | 51b4a3fc75351d6ecd2142c228d31a1f7ed52152 (patch) | |
tree | c28d0c11b71a56199a6308914a040e18a28b60ef /src/resources/obj.c | |
parent | 2b83174a87f5a1e4991cc9153309ad0f73450b44 (diff) |
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
Diffstat (limited to 'src/resources/obj.c')
-rw-r--r-- | src/resources/obj.c | 9 |
1 files changed, 8 insertions, 1 deletions
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 }; } |