mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-04 04:50:22 +00:00
Stopped timers don't trigger on TIMER ON
If a timer expires while stopped, it should trigger when TIMER ON is run. Instead, on QB64 it triggers randomly after the TIMER ON happens. The basic issue is that `qbevent` needs to be set to trigger the timer, but TIMER ON doesn't do that. The regular timer logic that does that already set it when the timer expired while sleeping, so it won't set it again. The simplest solution is to just alway set qbevent = 1 when TIMER ON is done. It's slightly less efficent but doesn't hurt to set it even when there are no timers that expired. Fixes: #293
This commit is contained in:
parent
f995f38e38
commit
d4ed371681
|
@ -2073,6 +2073,9 @@ void sub_timer(int32 i, int32 option, int32 passed) {
|
|||
// ref: uint8 active;//0=OFF, 1=ON, 2=STOP
|
||||
if (option == 1) { // ON
|
||||
ontimer[i].active = 1;
|
||||
|
||||
// This is necessary so that if a timer triggered while stopped we will run it now.
|
||||
qbevent = 1;
|
||||
return;
|
||||
}
|
||||
if (option == 2) { // OFF
|
||||
|
|
15
tests/compile_tests/timer/timer_delayed_run.bas
Normal file
15
tests/compile_tests/timer/timer_delayed_run.bas
Normal file
|
@ -0,0 +1,15 @@
|
|||
$Console:Only
|
||||
|
||||
On Timer(2) GoSub timerhand
|
||||
|
||||
' This first delay should not matter
|
||||
_Delay 3
|
||||
Timer On
|
||||
|
||||
' The timer should be triggered twice
|
||||
_Delay 5
|
||||
System
|
||||
|
||||
timerhand:
|
||||
Print "Timer!"
|
||||
return
|
2
tests/compile_tests/timer/timer_delayed_run.output
Normal file
2
tests/compile_tests/timer/timer_delayed_run.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
Timer!
|
||||
Timer!
|
12
tests/compile_tests/timer/timer_first_run.bas
Normal file
12
tests/compile_tests/timer/timer_first_run.bas
Normal file
|
@ -0,0 +1,12 @@
|
|||
$Console:Only
|
||||
|
||||
On Timer(2) GoSub timerhand
|
||||
Timer On
|
||||
|
||||
' Timer should be triggered twice
|
||||
_Delay 5
|
||||
System
|
||||
|
||||
timerhand:
|
||||
Print "Timer!"
|
||||
return
|
2
tests/compile_tests/timer/timer_first_run.output
Normal file
2
tests/compile_tests/timer/timer_first_run.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
Timer!
|
||||
Timer!
|
18
tests/compile_tests/timer/timer_stop.bas
Normal file
18
tests/compile_tests/timer/timer_stop.bas
Normal file
|
@ -0,0 +1,18 @@
|
|||
$Console:Only
|
||||
|
||||
On Timer(2) GoSub timerhand
|
||||
Timer On
|
||||
Timer Stop
|
||||
|
||||
' Timer will not trigger when stopped
|
||||
Sleep 3
|
||||
|
||||
' Timer should trigger immediately when started as two seconds have elapsed
|
||||
' while it was stopped
|
||||
Timer On
|
||||
Timer Off 'Shouldn't matter, timer triggers as soon as Timer On runs
|
||||
System
|
||||
|
||||
timerhand:
|
||||
Print "Timer!"
|
||||
return
|
1
tests/compile_tests/timer/timer_stop.output
Normal file
1
tests/compile_tests/timer/timer_stop.output
Normal file
|
@ -0,0 +1 @@
|
|||
Timer!
|
Loading…
Reference in a new issue