fix(timer) correctly handle deleting a timer in an other timer with repeat_count = 1
This commit is contained in:
@@ -283,19 +283,27 @@ static bool lv_timer_exec(lv_timer_t * timer)
|
||||
{
|
||||
if(timer->paused) return false;
|
||||
|
||||
if(timer->repeat_count == 0) {
|
||||
TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb);
|
||||
lv_timer_del(timer);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool exec = false;
|
||||
if(lv_timer_time_remaining(timer) == 0) {
|
||||
/* Decrement the repeat count before executing the timer_cb.
|
||||
* If any timer is deleted `if(timer->repeat_count == 0)` is not executed below
|
||||
* but at least the repeat count is zero and the timer can be deleted in the next round*/
|
||||
int32_t original_repeat_count = timer->repeat_count;
|
||||
if(timer->repeat_count > 0) timer->repeat_count--;
|
||||
timer->last_run = lv_tick_get();
|
||||
TIMER_TRACE("calling timer callback: %p", timer->timer_cb);
|
||||
if(timer->timer_cb) timer->timer_cb(timer);
|
||||
if(timer->timer_cb && original_repeat_count != 0) timer->timer_cb(timer);
|
||||
TIMER_TRACE("timer callback %p finished", timer->timer_cb);
|
||||
LV_ASSERT_MEM_INTEGRITY();
|
||||
|
||||
/*Delete if it was a one shot lv_timer*/
|
||||
if(timer_deleted == false) { /*The timer might be deleted by itself as well*/
|
||||
if(timer->repeat_count > 0) {
|
||||
timer->repeat_count--;
|
||||
}
|
||||
if(timer->repeat_count == 0) {
|
||||
TIMER_TRACE("deleting timer with %p callback because the repeat count is over", timer->timer_cb);
|
||||
lv_timer_del(timer);
|
||||
|
||||
Reference in New Issue
Block a user