Skip to content

Commit 43233b3

Browse files
committed
fix(timer): the callback will still run after the timer is removed
1 parent 85a1739 commit 43233b3

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/gui/widget/textcaret.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void TextCaret_OnDestroy(LCUI_Widget widget)
140140

141141
caret = Widget_GetData(widget, prototype);
142142
caret->task->active = FALSE;
143-
if (LCUITimer_Free(caret->timer_id) == 0) {
143+
if (LCUITimer_Free(caret->timer_id) != -1) {
144144
free(caret->task);
145145
caret->task = NULL;
146146
}

src/timer.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int LCUITimer_Free(int timer_id)
130130
{
131131
Timer timer;
132132
if (!self.active) {
133-
return -1;
133+
return -2;
134134
}
135135
LCUIMutex_Lock(&self.mutex);
136136
timer = FindTimer(timer_id);
@@ -148,7 +148,7 @@ int LCUITimer_Pause(int timer_id)
148148
{
149149
Timer timer;
150150
if (!self.active) {
151-
return -1;
151+
return -2;
152152
}
153153
LCUIMutex_Lock(&self.mutex);
154154
timer = FindTimer(timer_id);
@@ -165,7 +165,7 @@ int LCUITimer_Continue(int timer_id)
165165
{
166166
Timer timer;
167167
if (!self.active) {
168-
return -1;
168+
return -2;
169169
}
170170
LCUIMutex_Lock(&self.mutex);
171171
timer = FindTimer(timer_id);
@@ -183,7 +183,7 @@ int LCUITimer_Reset(int timer_id, long int n_ms)
183183
{
184184
Timer timer;
185185
if (!self.active) {
186-
return -1;
186+
return -2;
187187
}
188188
LCUIMutex_Lock(&self.mutex);
189189
timer = FindTimer(timer_id);
@@ -233,7 +233,7 @@ size_t LCUI_ProcessTimers(void)
233233
}
234234
/* 若需要重复使用,则重置剩余等待时间 */
235235
LinkedList_Unlink(&self.timers, node);
236-
LCUI_PostSimpleTask(timer->callback, timer->arg, NULL);
236+
timer->callback(timer->arg);
237237
if (timer->reuse) {
238238
timer->pause_ms = 0;
239239
timer->start_time = LCUI_GetTime();

0 commit comments

Comments
 (0)