Difficult to describe problem with CanvasGadget

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 841
Joined: Fri Jun 11, 2004 7:07 am

Difficult to describe problem with CanvasGadget

Post 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
User avatar
STARGÅTE
Addict
Addict
Posts: 2260
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Difficult to describe problem with CanvasGadget

Post by STARGÅTE »

no problem here (win 7, PB 5.30b4, x64)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Lebostein
Addict
Addict
Posts: 841
Joined: Fri Jun 11, 2004 7:07 am

Re: Difficult to describe problem with CanvasGadget

Post 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?
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: Difficult to describe problem with CanvasGadget

Post by bobobo »

no prob on win7 x86 pb 5.22 5.30 b4

(only when dragging the window the update is not shown)
사십 둘 .
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Difficult to describe problem with CanvasGadget

Post by Crusiatus Black »

PB 5.21 LTS x86 on Windows 7 Professional x64, I encountered no issues.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
marc_256
Addict
Addict
Posts: 858
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Difficult to describe problem with CanvasGadget

Post 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
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
mk-soft
Always Here
Always Here
Posts: 6329
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Difficult to describe problem with CanvasGadget

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: Difficult to describe problem with CanvasGadget

Post by BasicallyPure »

Try removing this line and see if that helps.

Code: Select all

SmartWindowRefresh(#Window, 1)
BP
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4996
Joined: Sun Apr 12, 2009 6:27 am

Re: Difficult to describe problem with CanvasGadget

Post 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
Egypt my love
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Difficult to describe problem with CanvasGadget

Post 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.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Post Reply