Timers randomly stop redrawing
Posted: Mon Feb 20, 2006 8:59 pm
Alright, I finished my TimerPack now, but there's still an annoying bug that I can't get fixed. The timerwindow consists of 6 timers, and the actual timer display is created by rendering a new image every time the timer ticks. I use Threads for these processes. The code for the procedures is as follows:
There are 6 of these procedures, but they're all the same but for the timernames (timer1 to timer6) and the thread handles (Thread1ID to Thread6ID)
Then there's still the code that initiates these threads. They are responses to clicks on either the set or stop buttons of each timer:
I haven't been able to discover the problem. It is really rare, it only happens when the user clicks on a button, or when a sound is played, but only about every 20 times. The timer still keeps ticking, only the text (image) of that particular timer stops updating...
Code: Select all
Procedure timer1(timer1)
While timer1.l >= 0
time_s() = MsToTimeDisplay(timer1.l,1)
UseImage(#txtTimeEarn)
StartDrawing(ImageOutput())
Box(0,0,60,15,RGB(153,0,51))
DrawingMode(1)
DrawingFont(UseFont(#fontID2))
FrontColor(255,255,255)
Locate(1,1):DrawText(time_s(0)+":"+time_s(1)+":"+time_s(2))
StopDrawing()
SetGadgetState(#txtTimeEarn,UseImage(#txtTimeEarn))
If timer1.l < 1000 And Thread1ID <> 0
KillThread(Thread1ID)
EndIf
timer1.l = timer1.l - 1000
Delay(1000)
Wend
If IsSoundPlaying(0) = 0
PlaySound(0,0)
EndIf
While IsSoundPlaying(0) <> 0
; do nothing
Wend
EndProcedure
Then there's still the code that initiates these threads. They are responses to clicks on either the set or stop buttons of each timer:
Code: Select all
Case #cmdSetEarn
timer1 = valTimer1.l
If Thread1ID.l <> 0
KillThread(Thread1ID)
EndIf
Thread1ID.l = CreateThread(@timer1(),valTimer1.l)
Case #cmdStopEarn
If Thread1ID.l <> 0
KillThread(Thread1ID)
EndIf
Case #cmdSetStudy
timer2 = valTimer2.l
If Thread2ID.l <> 0
KillThread(Thread2ID)
EndIf
Thread2ID.l = CreateThread(@timer2(),valTimer2.l)
Case #cmdStopStudy
If Thread2ID.l <> 0
KillThread(Thread2ID)
EndIf
Case #cmdSetCrime
timer3 = valTimer3.l
If Thread3ID.l <> 0
KillThread(Thread3ID)
EndIf
Thread3ID.l = CreateThread(@timer3(),valTimer3.l)
Case #cmdStopCrime
If Thread3ID.l <> 0
KillThread(Thread3ID)
EndIf
Case #cmdSetTravel
timer4 = valTimer4.l
If Thread4ID.l <> 0
KillThread(Thread4ID)
EndIf
Thread4ID.l = CreateThread(@timer4(),valTimer4.l)
Case #cmdStopTravel
If Thread4ID.l <> 0
KillThread(Thread4ID)
EndIf
Case #cmdSetKill
timer5 = valTimer5.l
If Thread5ID.l <> 0
KillThread(Thread5ID)
EndIf
Thread5ID.l = CreateThread(@timer5(),valTimer5.l)
Case #cmdStopKill
If Thread5ID.l <> 0
KillThread(Thread5ID)
EndIf
Case #cmdSetOther
timer6 = valTimer6.l
If Thread6ID.l <> 0
KillThread(Thread6ID)
EndIf
Thread6ID.l = CreateThread(@timer6(),valTimer6.l)
Case #cmdStopOther
If Thread6ID.l <> 0
KillThread(Thread6ID)
EndIf