From 9607ea5c0a28d1a3f5812c6fdc4822ab4b48cde2 Mon Sep 17 00:00:00 2001 From: Ryan Roden-Corrent Date: Wed, 22 Sep 2021 07:04:10 -0400 Subject: [PATCH] Use unsigned int for animation count. (#2002) LoadModelAnimations takes an `int` for the animation count parameter. The animation count should never be negative, so it makes sense to specify it as unsigned in the API. This matches the API for UnloadModelAnimations, which expects an unsigned int. Both GLTF and IQMM also store the animation count internally as unsigned, and we were casting to a signed int for no reason. GLTF actually uses `size_t` internally, so we're technically risking overflow, but having 2^32 animations seems unlikely. --- src/raylib.h | 2 +- src/rmodels.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index b8d320b0d..83e84a4f9 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1436,7 +1436,7 @@ RLAPI void SetMaterialTexture(Material *material, int mapType, Texture2D texture RLAPI void SetModelMeshMaterial(Model *model, int meshId, int materialId); // Set material for a mesh // Model animations loading/unloading functions -RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, int *animCount); // Load model animations from file +RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, unsigned int *animCount); // Load model animations from file RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, int frame); // Update model animation pose RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data RLAPI void UnloadModelAnimations(ModelAnimation* animations, unsigned int count); // Unload animation array data diff --git a/src/rmodels.c b/src/rmodels.c index 8319814b4..13aa11670 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -128,11 +128,11 @@ static Model LoadOBJ(const char *fileName); // Load OBJ mesh data #endif #if defined(SUPPORT_FILEFORMAT_IQM) static Model LoadIQM(const char *fileName); // Load IQM mesh data -static ModelAnimation *LoadIQMModelAnimations(const char *fileName, int *animCount); // Load IQM animation data +static ModelAnimation *LoadIQMModelAnimations(const char *fileName, unsigned int *animCount); // Load IQM animation data #endif #if defined(SUPPORT_FILEFORMAT_GLTF) static Model LoadGLTF(const char *fileName); // Load GLTF mesh data -static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, int *animCount); // Load GLTF animation data +static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, unsigned int *animCount); // Load GLTF animation data static void LoadGLTFMaterial(Model *model, const char *fileName, const cgltf_data *data); static void LoadGLTFMesh(cgltf_data *data, cgltf_mesh *mesh, Model *outModel, Matrix currentTransform, int *primitiveIndex, const char *fileName); static void LoadGLTFNode(cgltf_data *data, cgltf_node *node, Model *outModel, Matrix currentTransform, int *primitiveIndex, const char *fileName); @@ -1607,7 +1607,7 @@ void SetModelMeshMaterial(Model *model, int meshId, int materialId) } // Load model animations from file -ModelAnimation *LoadModelAnimations(const char *fileName, int *animCount) +ModelAnimation *LoadModelAnimations(const char *fileName, unsigned int *animCount) { ModelAnimation *animations = NULL; @@ -4072,7 +4072,7 @@ static Model LoadIQM(const char *fileName) } // Load IQM animation data -static ModelAnimation* LoadIQMModelAnimations(const char *fileName, int *animCount) +static ModelAnimation* LoadIQMModelAnimations(const char *fileName, unsigned int *animCount) { #define IQM_MAGIC "INTERQUAKEMODEL" // IQM file magic number #define IQM_VERSION 2 // only IQM version 2 supported @@ -5067,7 +5067,7 @@ static void BindGLTFPrimitiveToBones(Model *model, const cgltf_data *data, int p } // LoadGLTF loads in animation data from given filename -static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, int *animCount) +static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, unsigned int *animCount) { /*********************************************************************************** @@ -5102,7 +5102,7 @@ static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, int *animCo result = cgltf_load_buffers(&options, data, fileName); if (result != cgltf_result_success) TRACELOG(LOG_WARNING, "MODEL: [%s] unable to load glTF animations data", fileName); animations = RL_MALLOC(data->animations_count*sizeof(ModelAnimation)); - *animCount = (int)data->animations_count; + *animCount = (unsigned int)data->animations_count; for (unsigned int a = 0; a < data->animations_count; a++) {