From fd3cbac7a9b47936d28cfcf11b7781c563779129 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sun, 25 Feb 2024 15:07:53 -0800 Subject: Log asset load failures. --- gfx/src/asset/asset_cache.c | 53 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/gfx/src/asset/asset_cache.c b/gfx/src/asset/asset_cache.c index 0a9b1f2..1d64d66 100644 --- a/gfx/src/asset/asset_cache.c +++ b/gfx/src/asset/asset_cache.c @@ -13,8 +13,54 @@ #include #include +#include #include +static void log_model_load_failure(const LoadModelCmd* cmd) { + assert(cmd); + + switch (cmd->origin) { + case AssetFromFile: + log_error("Failed to load model: %s", mstring_cstr(&cmd->filepath)); + break; + case AssetFromMemory: + log_error("Failed to load model: %p", cmd->data); + break; + } +} + +static void log_texture_load_failure(const LoadTextureCmd* cmd) { + assert(cmd); + + switch (cmd->origin) { + case AssetFromFile: + switch (cmd->type) { + case LoadTexture: + log_error( + "Failed to load texture: %s", + mstring_cstr(&cmd->data.texture.filepath)); + break; + case LoadCubemap: + log_error( + "Failed to load cubemap texture: %s", + mstring_cstr(&cmd->data.cubemap.filepaths.filepath_pos_x)); + break; + } + break; + case AssetFromMemory: + switch (cmd->type) { + case LoadTexture: + log_error("Failed to load texture: %p", cmd->data.texture.data); + break; + case LoadCubemap: + log_error( + "Failed to load texture: %p", cmd->data.cubemap.buffers.data_pos_x); + break; + } + break; + } +} + static Hash calc_model_hash(const LoadModelCmd* cmd) { assert(cmd); switch (cmd->origin) { @@ -166,8 +212,11 @@ Model* gfx_load_model(Gfx* gfx, const LoadModelCmd* cmd) { .model = model, }; log_model_loaded(cmd); + return clone_model(model); + } else { + log_model_load_failure(cmd); + return 0; } - return clone_model(model); } const Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { @@ -193,6 +242,8 @@ const Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { .hash = hash, .texture = texture, }; + } else { + log_texture_load_failure(cmd); } return texture; } -- cgit v1.2.3