From a86e8b9bdd0488d4534e0e3fd5b41c8b4575c777 Mon Sep 17 00:00:00 2001 From: Valtteri Koskivuori Date: Sun, 27 Oct 2024 18:22:13 +0200 Subject: [PATCH] lib: Fix redundant mmap() calls for textures Only need to mmap() if we haven't loaded that texture yet. --- src/lib/nodes/colornode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/nodes/colornode.c b/src/lib/nodes/colornode.c index 358ea8e5..57012920 100644 --- a/src/lib/nodes/colornode.c +++ b/src/lib/nodes/colornode.c @@ -44,7 +44,6 @@ const struct colorNode *build_color_node(struct cr_scene *s_ext, const struct cr windowsFixPath(full); } const char *path = full ? full : desc->arg.image.full_path; - file_data data = file_load(path); struct texture *tex = NULL; // Note: We also deduplicate texture loads here, which ideally shouldn't be necessary. for (size_t i = 0; i < scene->textures.count; ++i) { @@ -53,13 +52,14 @@ const struct colorNode *build_color_node(struct cr_scene *s_ext, const struct cr } } if (!tex) { + file_data data = file_load(path); tex = load_texture(path, data); texture_asset_arr_add(&scene->textures, (struct texture_asset){ .path = stringCopy(path), .t = tex }); + file_free(&data); } - file_free(&data); const struct colorNode *new = newImageTexture(&s, tex, desc->arg.image.options); if (full) free(full); return new;