Guard animation examples against missing model resources
LoadModelAnimations() returns NULL with animCount = 0 when the glTF file can not be read, and the animation examples then crash dereferencing animations by index. Reported as a segfault in models_animation_blending when resources/models/gltf/robot.glb is missing. The same pattern hits three more examples: - models_animation_timing: update loop is guarded but the UI drawing reads anims[animIndex] unconditionally every frame - models_animation_gpu_skinning: modulo by zero animCount on key press, then anims[animIndex] read - models_animation_blend_custom: index clamping does not help because the array itself is NULL All four now exit early with a warning, unloading what was created.
This commit is contained in:
parent
abe23bf82d
commit
59cf1df522
4 changed files with 40 additions and 0 deletions
|
|
@ -46,6 +46,16 @@ int main(void)
|
|||
int animCount = 0;
|
||||
ModelAnimation *anims = LoadModelAnimations("resources/models/gltf/robot.glb", &animCount);
|
||||
|
||||
// WARNING: Exit if example resources could not be loaded
|
||||
if ((model.meshCount == 0) || (animCount == 0))
|
||||
{
|
||||
TraceLog(LOG_WARNING, "MODEL: Example resources could not be loaded");
|
||||
UnloadModelAnimations(anims, animCount);
|
||||
UnloadModel(model);
|
||||
CloseWindow();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Animation playing variables
|
||||
int animIndex = 10; // Current animation playing
|
||||
float animCurrentFrame = 0.0f; // Current animation frame (supporting interpolated frames)
|
||||
|
|
|
|||
Loading…
Reference in a new issue