Seltsames Phänomen bei zwei Timern

Hier werden, insbesondere in den Beta-Phasen, Bugmeldungen gepostet. Das offizielle BugForum ist allerdings hier.
walbus
Beiträge: 137
Registriert: 03.03.2013 20:50

Seltsames Phänomen bei zwei Timern

Beitrag von walbus »

Hallo
bitte schaut euch das mal an, ob euch dazu was einfällt.

Ich hatte diesen komischen Effekt und habe mal nach der Ursache gesucht.

Wird ein File Selector aufgemacht, etwas stehen gelassen und dann abgebrochen, fällt der voreingestellte 40ms Schritt Timer aus.
Dies passiert auch beim verschieben des Fensters oder bei einer Alert Box.
Steht zum Beispiel eine Alert Box 5 Minuten und wird dann beendet, geht zuerst mal gar nix mehr.
Die Linien rasen und das Fenster freezt.
Es passiert nur wenn ein zweiter Timer aktiviert ist.
Fixen kann man es zB. indem man einen Button in der main loop zyklisch aufruft.

Code: Alles auswählen

Procedure Linie(x.i, y.i, xx.i, yy.i, shift.a, color.l, lr.i)
   
  ; Achtung Plot unterstützt kein Clipping
   
   Protected a.i, dx.i, dy.i, addval.i = 1
   Protected *plotX.Integer = @xx, *plotY.Integer = @yy
   
   If Abs(x - xx) <= Abs(y - yy) ; Winkel größer 45°
      Swap x, y
      Swap xx, yy
      *plotX = @yy
      *plotY = @xx
   EndIf
      
   If x < xx
      Swap x, xx
      Swap y, yy
   EndIf
   
   If y < yy
      y = 2 * yy - y
      addval = -1
   EndIf
   
   dy = 2 * (y - yy)
   a  = x - xx
   dx = 2 * a
   
   While xx <= x
      
      If shift & 1
         Plot(*plotX\i, *plotY\i, color)
      EndIf
      
      If lr
         shift = (shift << 1) | ((shift >> 7) & $7f)
      Else
         shift = ((shift >> 1) & $7F) | (shift << 7)
      EndIf
      
      xx + 1
      a - dy
      If a <= 0
         a + dx
         yy + addval
      EndIf
   Wend
   
EndProcedure

;-------------------------------------------

Procedure Liniego(x.i, y.i, xx.i, yy.i, color.l, move.i, shift.a, lr.i)
   
  For i=0 To move
  shift = (shift << 1) | ((shift >> 7) & $7f)  
  Next i

  Linie(x, y, xx, yy, shift, color, lr)     

EndProcedure

;-------------------------------------------

Procedure Boxgo(x.i, y.i, xx.i, yy.i, color.l, move.i, shift.a, lr.i)

  xx - 1 : yy - 1
  
 If lr
   Liniego(x, y, x + xx, y, color, move, shift, 1)
   Liniego(x + xx, y, x + xx, y + yy, color, move, shift, 1)
   Liniego(x, y + yy, x + xx, y + yy, color, move, shift, 0)
   Liniego(x, y + yy, x, y, color, move, shift, 0)
  Else
   Liniego(x, y, x + xx, y, color, move, shift, 0)
   Liniego(x + xx, y, x + xx, y + yy, color, move, shift, 0)
   Liniego(x, y + yy, x + xx, y + yy, color, move, shift, 1)
   Liniego(x, y + yy, x, y, color, move, shift, 1)
 EndIf
   
EndProcedure

; --------Loop-----------------------------

ExamineDesktops()

If OpenWindow (0, DesktopWidth(0) / 2 - 200, DesktopHeight(0) / 2 - 250, 500, 300, "")
  
  CanvasGadget(0, 0, 0, 500 , 200)
  AddWindowTimer(0, 1, 40)
  AddWindowTimer(0, 2, 100) ; Ist Dieser Timer deaktiviert, ist es weg ##########################
  
  ButtonGadget(1,150,230,200,40,"Hit me")
  

  Repeat    
    
    
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow:
        End
        
      Case #PB_Event_Timer
        
      If EventTimer()=1
        
        If StartDrawing(CanvasOutput(0))
          Box   (0, 0, 500, 200, $FFFFFF)
          DrawingMode(#PB_2DDrawing_Outlined) ; Zeichnen von Flächen erfolgt nicht ausgefüllt
          
          Boxgo (148, 68, 204, 104, $0 , move, %11110000,1)
          Boxgo (149, 69, 202, 102, $0 , move, %11110000,1)
          Boxgo (150, 70, 200, 100, $0 , move, %11110000,1)
          
          StopDrawing()
        EndIf
        
        move +1 ; Animations Counter für bewegte Linien
        If move >7 : move = 0 : EndIf
        
       ; ButtonGadget(2,-100,0,0,0,"") ; Ist dieser Button aktiviert, ist es weg ##########################

      EndIf 
        
      Case #PB_Event_Gadget
        If EventGadget()
          MessageRequester("Test","Warte mal wenigstens eine Minute und schau dann mal nach den bewegten Linien")
        EndIf
        
    EndSelect
    
  ForEver
  
EndIf
Gruss Werner
Zuletzt geändert von walbus am 14.09.2013 14:09, insgesamt 2-mal geändert.
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Seltsames Phänomen bei zwei Timern

Beitrag von ts-soft »

Timer haben nur eine geringe Priorität. Wenn Fenster bewegt oder modale Dialog aufgerufen werden, fällt das
Timer-Event unter den Tisch.

Etwas besser funktioniert es mit BindEvent() oder mit einem TimerCallback per API.

Ist aber IMHO kein Bug!
Bitte nach z.B. Anfänger verschieben.
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
walbus
Beiträge: 137
Registriert: 03.03.2013 20:50

Re: Seltsames Phänomen bei zwei Timern

Beitrag von walbus »

Ja, danke,
mit der Anbindung der Timer über BindEvent ist es weg.
Die Auswirkung der geringen Priorität der Timer hatte ich so heftig nicht erwartet.
Antworten