From eb741d4dc4fbd9f2ad0fbd0193df7d1fceb35c94 Mon Sep 17 00:00:00 2001 From: kdx Date: Sun, 26 Mar 2023 22:38:18 +0200 Subject: tzr style resource usage --- headers/TZR_resource.h | 2 ++ sources/TZR_DrawImage.c | 5 +++++ sources/TZR_LoadResourceTyped.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/headers/TZR_resource.h b/headers/TZR_resource.h index 06f0763..87373f0 100644 --- a/headers/TZR_resource.h +++ b/headers/TZR_resource.h @@ -1,6 +1,8 @@ #pragma once #include "TZR_types.h" +#define TZR_RES TZR_LoadResource + /* Return 0 on error. */ [[nodiscard]] TZR_Uint TZR_LoadResourceFromMemory(TZR_ResourceType type, const void *data, int size); diff --git a/sources/TZR_DrawImage.c b/sources/TZR_DrawImage.c index 862d94c..b9b4606 100644 --- a/sources/TZR_DrawImage.c +++ b/sources/TZR_DrawImage.c @@ -9,6 +9,11 @@ int _TZR_DrawImage(const TZR_DrawImageArgs *args) { + if (args->id == 0) { + fprintf(stderr, "args->id is 0\n"); + return -1; + } + if (TZR_GetResourceType(args->id) != TZR_RES_IMAGE) { fprintf(stderr, "%u isn't an image\n", args->id); return -1; diff --git a/sources/TZR_LoadResourceTyped.c b/sources/TZR_LoadResourceTyped.c index 3c38ee2..126737b 100644 --- a/sources/TZR_LoadResourceTyped.c +++ b/sources/TZR_LoadResourceTyped.c @@ -10,7 +10,7 @@ TZR_LoadResourceTyped(TZR_ResourceType type, const char *path) for (TZR_Uint i = 0; i < ___tzr_resources_size; i++) if (___tzr_resources[i].type == type && strcmp(___tzr_resources[i].path, path) == 0) - return i; + return i + 1; FILE *const fp = fopen(path, "rb"); if (fp == NULL) { perror(path); -- cgit v1.2.3