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
|
|
@ -81,6 +81,16 @@ int main(void)
|
|||
int animCount = 0;
|
||||
ModelAnimation *anims = LoadModelAnimations("resources/models/gltf/greenman.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;
|
||||
}
|
||||
|
||||
// Use specific animation indices: 2-walk/move, 3-attack
|
||||
int animIndex0 = 2; // Walk/Move animation (index 2)
|
||||
int animIndex1 = 3; // Attack animation (index 3)
|
||||
|
|
|
|||
|
|
@ -71,6 +71,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
|
||||
// NOTE: Two animations are played with a smooth transition between them
|
||||
int currentAnimPlaying = 0; // Current animation playing (0 o 1)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,16 @@ int main(void)
|
|||
int animCount = 0;
|
||||
ModelAnimation *anims = LoadModelAnimations("resources/models/gltf/greenman.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
|
||||
unsigned int animIndex = 0; // Current animation playing
|
||||
unsigned int animCurrentFrame = 0; // Current animation frame
|
||||
|
|
|
|||
|
|
@ -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