Timers randomly stop redrawing

Just starting out? Need help? Post your questions and find answers here.
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Timers randomly stop redrawing

Post by Roger »

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:

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
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:

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
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...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I didn't read your post but did you compile with threadsafe?
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post by Roger »

Where do I find that? :oops: ( I know I should have bothered reading the documentation )

Edit: I suppose it's version 4, as I can't find it in 3.94. I'll have to upgrade soon. However, that does not change the fact that this bug is quite strange. It sometimes happens that the finishing of one timer causes another timer to stop updating - yet, that timer still keeps ticking (I can hear the sound when it is 0), only the updating of the image(text) doesnt work in that case...
Post Reply