Page 1 of 1

Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 11:26 am
by Lebostein
Very strange (if Debugger = Off):

Why the rectangle stops with blinking (or blinking slow or flickers only) some times? As long as I move the mouse cursor, blinking is correct with a delay of 500 ms.
But If I turn on the Debugger (and print the word "Update" every 500 ms) then it works without problems!

Code: Select all

#Window = 0
#GadgetCanvas = 1
#Timer = 1

Global col1 = $0000FF
Global col2 = $FFFFFF

OpenWindow(#Window, 0, 0, 800, 600, "Test", #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
SmartWindowRefresh(#Window, 1)
CanvasGadget(#GadgetCanvas, 10, 10, 640, 480)
AddWindowTimer(#Window, #Timer, 500)

CreateImage(0, 320, 240, 24, $000000)
StartDrawing(ImageOutput(0))
For i = 0 To 239
Line(0, i, 320, 1, RGB(i,i,i))
Next i
StopDrawing()

Procedure UpdateCanvas()

  Debug "Update"
  CopyImage(0,1)
  StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Outlined)
  Box(10,10,100,100,col1)
  StopDrawing()
  Swap col1, col2
  ResizeImage(1, 320 * 2, 240 * 2, #PB_Image_Raw)
  SetGadgetAttribute(#GadgetCanvas, #PB_Canvas_Image, ImageID(1))

EndProcedure

Repeat

  Event = WaitWindowEvent(10)

  Select Event
  Case #PB_Event_Timer: If EventTimer() = #Timer: UpdateCanvas(): EndIf
  EndSelect

Until Event = #PB_Event_CloseWindow

Re: Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 12:10 pm
by STARGÅTE
no problem here (win 7, PB 5.30b4, x64)

Re: Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 12:23 pm
by Lebostein
I use Windows XP and Mac OS X Mavericks here. And I see the problem with both systems.

I have tested it with Windows XP on a virtual machine (virtualbox) on Linux just now. And it works.... what is going on?

Re: Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 12:56 pm
by bobobo
no prob on win7 x86 pb 5.22 5.30 b4

(only when dragging the window the update is not shown)

Re: Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 2:56 pm
by Crusiatus Black
PB 5.21 LTS x86 on Windows 7 Professional x64, I encountered no issues.

Re: Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 3:34 pm
by marc_256
WIN8.1 x64, PB5.22LST x64, no problems here...

I know when I used WinXP 32, I had also some problem...
but I do not remember what I did then.

Inserting delay(1) maybe ??

marc

Re: Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 6:11 pm
by mk-soft
No problem on Maverick (Mac Mini I5) PB 5.22 X86-X64, PB 5.30 X64

:?:

P.S. It´s only stop when Menu activate

Re: Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 7:36 pm
by BasicallyPure
Try removing this line and see if that helps.

Code: Select all

SmartWindowRefresh(#Window, 1)
BP

Re: Difficult to describe problem with CanvasGadget

Posted: Mon Jun 23, 2014 8:41 pm
by RASHAD
Try using Thread to have constant time delay

Code: Select all

#Window = 0
#GadgetCanvas = 1
#Timer = 1

Global col1 = $0000FF
Global col2 = $FFFFFF

Procedure UpdateCanvas(parameter)
Repeat
;Delay(500)
  Debug "Update"
  CopyImage(0,1)
  StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Outlined)
  Box(10,10,100,100,col1)
  StopDrawing()
  Swap col1, col2
  ResizeImage(1, 320 * 2, 240 * 2, #PB_Image_Raw)
  SetGadgetAttribute(#GadgetCanvas, #PB_Canvas_Image, ImageID(1))
  Delay(500)
ForEver

EndProcedure

OpenWindow(#Window, 0, 0, 800, 600, "Test", #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
;SmartWindowRefresh(#Window, 1)
CanvasGadget(#GadgetCanvas, 10, 10, 640, 480)
;AddWindowTimer(#Window, #Timer, 500)

CreateImage(0, 320, 240, 24, $000000)
StartDrawing(ImageOutput(0))
For i = 0 To 239
Line(0, i, 320, 1, RGB(i,i,i))
Next i
StopDrawing()

CreateThread(@UpdateCanvas(),23)

Repeat

  Event = WaitWindowEvent(10)

;   Select Event
;   Case #PB_Event_Timer: If EventTimer() = #Timer: UpdateCanvas(): EndIf
;   EndSelect

Until Event = #PB_Event_CloseWindow
Edit :Modified for best performance

Re: Difficult to describe problem with CanvasGadget

Posted: Tue Jun 24, 2014 4:18 pm
by BorisTheOld
Lebostein wrote:.... what is going on?
It's the nature of applications that use a message loop -- timing is everything.

That's why a GUI flickers when resizing a window, or why a screen freezes when the code is in a compute-bound loop.

It's just good luck that your code works on some systems, and bad luck that it doesn't work on others. :)

You need to restructure your code so that it doesn't depend on the operating environment.