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.
This commit is contained in:
Ryan Roden-Corrent 2021-09-22 07:04:10 -04:00 committed by GitHub
parent 8a434b4fd4
commit 9607ea5c0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -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 RLAPI void SetModelMeshMaterial(Model *model, int meshId, int materialId); // Set material for a mesh
// Model animations loading/unloading functions // 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 UpdateModelAnimation(Model model, ModelAnimation anim, int frame); // Update model animation pose
RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data
RLAPI void UnloadModelAnimations(ModelAnimation* animations, unsigned int count); // Unload animation array data RLAPI void UnloadModelAnimations(ModelAnimation* animations, unsigned int count); // Unload animation array data

View File

@ -128,11 +128,11 @@ static Model LoadOBJ(const char *fileName); // Load OBJ mesh data
#endif #endif
#if defined(SUPPORT_FILEFORMAT_IQM) #if defined(SUPPORT_FILEFORMAT_IQM)
static Model LoadIQM(const char *fileName); // Load IQM mesh data 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 #endif
#if defined(SUPPORT_FILEFORMAT_GLTF) #if defined(SUPPORT_FILEFORMAT_GLTF)
static Model LoadGLTF(const char *fileName); // Load GLTF mesh data 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 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 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); 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 // Load model animations from file
ModelAnimation *LoadModelAnimations(const char *fileName, int *animCount) ModelAnimation *LoadModelAnimations(const char *fileName, unsigned int *animCount)
{ {
ModelAnimation *animations = NULL; ModelAnimation *animations = NULL;
@ -4072,7 +4072,7 @@ static Model LoadIQM(const char *fileName)
} }
// Load IQM animation data // 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_MAGIC "INTERQUAKEMODEL" // IQM file magic number
#define IQM_VERSION 2 // only IQM version 2 supported #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 // 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); result = cgltf_load_buffers(&options, data, fileName);
if (result != cgltf_result_success) TRACELOG(LOG_WARNING, "MODEL: [%s] unable to load glTF animations 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)); 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++) for (unsigned int a = 0; a < data->animations_count; a++)
{ {