From 7e0a6052fba7014244e8247e155e386c70c022d8 Mon Sep 17 00:00:00 2001 From: Lincoln Ramsay Date: Wed, 26 Nov 2025 19:54:18 +0800 Subject: [PATCH] Fix bad custom animation example The custom animation example suggests that a stack-allocated AnimationImplementation variable can be used, but this is incorrect. The variable is not copied and so must remain valid while the animation runs. Rework the example to use a global variable for the implementation. Signed-off-by: Lincoln Ramsay --- .../_guides/graphics-and-animations/animations.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/source/_guides/graphics-and-animations/animations.md b/source/_guides/graphics-and-animations/animations.md index ecbb446..3687363 100644 --- a/source/_guides/graphics-and-animations/animations.md +++ b/source/_guides/graphics-and-animations/animations.md @@ -175,6 +175,13 @@ static void implementation_update(Animation *animation, static void implementation_teardown(Animation *animation) { APP_LOG(APP_LOG_LEVEL_INFO, "Animation finished!"); } + +// This needs to exist while the event loop runs +static const AnimationImplementation s_implementation = { + .setup = implementation_setup, + .update = implementation_update, + .teardown = implementation_teardown +}; ``` Once these are in place, create a new ``Animation`` , specifying the new custom @@ -187,12 +194,7 @@ animation_set_delay(animation, 1000); animation_set_duration(animation, 1000); // Create the AnimationImplementation -const AnimationImplementation implementation = { - .setup = implementation_setup, - .update = implementation_update, - .teardown = implementation_teardown -}; -animation_set_implementation(animation, &implementation); +animation_set_implementation(animation, &s_implementation); // Play the Animation animation_schedule(animation);