Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent long delay caused by overflow when repeat period < frame duration #1028

Closed
wants to merge 1 commit into from

Conversation

sjahu
Copy link

@sjahu sjahu commented Sep 28, 2022

I noticed that when the repeat period for sendPulseDistanceWidthFromArray or sendPulseDistanceWidth happens to be shorter than the time it actually took to send a frame, the calculation for the delay overflows. This leads to an indefinite/very long delay, basically hanging the program "forever".

This PR adds a guard to prevent this overflow. Rather than hanging, when the repeat period is shorter than the actual frame duration, the program will proceed immediately to the next repetition. This doesn't feel totally correct since it means the period will be wrong, but IMO it's a better and more forgiving result than the status quo.

NB: Calling these methods with such a short repetition period is probably a mistake (as it was in my case). Still, this fix might save some future users some trouble.

@ArminJo ArminJo closed this in a975405 Sep 28, 2022
@ArminJo
Copy link
Collaborator

ArminJo commented Sep 28, 2022

Hi Stephen,
thank you very much for your PR. 🥇
I merged it manually, since I slightly changed the code and applied the patch to all 4 places, even to the two ones, where it should not be neccesary. But this makes the code more consistent and for my surprise the code size does not increase with your patch 😀 .
Best regards
Armin

@sjahu sjahu changed the title Prevent long delay caused by overflow when frame duration < repeat period Prevent long delay caused by overflow when repeat period < frame duration Sep 28, 2022
@sjahu
Copy link
Author

sjahu commented Sep 28, 2022

🎉

@sjahu sjahu deleted the fix-repeat-overflow branch October 5, 2022 19:54
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.

None yet

2 participants