Skip to content

Conversation

@a1291762
Copy link

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.

For brevity, I have used a static qualifier to give the variable global lifespan without making it an explicit global variable.

I have also added a note about the lifetime of the AnimationImplementation variable.

The API documentation is not clear, and following this example led me to a crashing app. I am seemingly not the only one that has had this happen. See https://stackoverflow.com/questions/35661791/pebble-how-to-create-a-custom-animation for the same problem (though it's not clear if they also based their code on the example).

Copy link
Contributor

@C-D-Lewis C-D-Lewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caught me a few times 👍

@FlynnD273
Copy link

I think you should make the animation variable static const as well, and move the animation call logic into a separate function (named something like init_and_start_animation) to clarify the scope a little better.

Copy link
Member

@Sorixelle Sorixelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just needs a Signed-off-by and it's good to go!

@a1291762
Copy link
Author

I think you should make the animation variable static const as well, and move the animation call logic into a separate function (named something like init_and_start_animation) to clarify the scope a little better.

If I'm going to do a larger change, it would include both creating and destroying the Animation* variable. Just making it static isn't very useful (and it's allocated on the heap, so it doesn't have the scope problems that AnimationImplmentation has).

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.

But also, the animation variable should not be stack-allocated, as
this makes it difficult to destroy it later.

Rework the example to use global variables for the animation and
implementation.

Signed-off-by: Lincoln Ramsay <[email protected]>
@a1291762 a1291762 force-pushed the fix_animation_documentation branch from 889a2fc to 169b710 Compare November 27, 2025 03:00
@a1291762
Copy link
Author

I updated the example to be more "complete", and hopefully representitive of how people will actually use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants