Skip to content

Commit 7e0a605

Browse files
committed
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 <a1291762@gmail.com>
1 parent 1d48fd9 commit 7e0a605

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

source/_guides/graphics-and-animations/animations.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ static void implementation_update(Animation *animation,
175175
static void implementation_teardown(Animation *animation) {
176176
APP_LOG(APP_LOG_LEVEL_INFO, "Animation finished!");
177177
}
178+
179+
// This needs to exist while the event loop runs
180+
static const AnimationImplementation s_implementation = {
181+
.setup = implementation_setup,
182+
.update = implementation_update,
183+
.teardown = implementation_teardown
184+
};
178185
```
179186
180187
Once these are in place, create a new ``Animation`` , specifying the new custom
@@ -187,12 +194,7 @@ animation_set_delay(animation, 1000);
187194
animation_set_duration(animation, 1000);
188195
189196
// Create the AnimationImplementation
190-
const AnimationImplementation implementation = {
191-
.setup = implementation_setup,
192-
.update = implementation_update,
193-
.teardown = implementation_teardown
194-
};
195-
animation_set_implementation(animation, &implementation);
197+
animation_set_implementation(animation, &s_implementation);
196198
197199
// Play the Animation
198200
animation_schedule(animation);

0 commit comments

Comments
 (0)