Skip to content

Commit

Permalink
fix(timer): the callback will still run after the timer is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Mar 1, 2020
1 parent 85a1739 commit 43233b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/gui/widget/textcaret.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void TextCaret_OnDestroy(LCUI_Widget widget)

caret = Widget_GetData(widget, prototype);
caret->task->active = FALSE;
if (LCUITimer_Free(caret->timer_id) == 0) {
if (LCUITimer_Free(caret->timer_id) != -1) {
free(caret->task);
caret->task = NULL;
}
Expand Down
10 changes: 5 additions & 5 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int LCUITimer_Free(int timer_id)
{
Timer timer;
if (!self.active) {
return -1;
return -2;
}
LCUIMutex_Lock(&self.mutex);
timer = FindTimer(timer_id);
Expand All @@ -148,7 +148,7 @@ int LCUITimer_Pause(int timer_id)
{
Timer timer;
if (!self.active) {
return -1;
return -2;
}
LCUIMutex_Lock(&self.mutex);
timer = FindTimer(timer_id);
Expand All @@ -165,7 +165,7 @@ int LCUITimer_Continue(int timer_id)
{
Timer timer;
if (!self.active) {
return -1;
return -2;
}
LCUIMutex_Lock(&self.mutex);
timer = FindTimer(timer_id);
Expand All @@ -183,7 +183,7 @@ int LCUITimer_Reset(int timer_id, long int n_ms)
{
Timer timer;
if (!self.active) {
return -1;
return -2;
}
LCUIMutex_Lock(&self.mutex);
timer = FindTimer(timer_id);
Expand Down Expand Up @@ -233,7 +233,7 @@ size_t LCUI_ProcessTimers(void)
}
/* 若需要重复使用,则重置剩余等待时间 */
LinkedList_Unlink(&self.timers, node);
LCUI_PostSimpleTask(timer->callback, timer->arg, NULL);
timer->callback(timer->arg);
if (timer->reuse) {
timer->pause_ms = 0;
timer->start_time = LCUI_GetTime();
Expand Down

0 comments on commit 43233b3

Please sign in to comment.