Initial graphics screen does not display.

Just starting out? Need help? Post your questions and find answers here.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Initial graphics screen does not display.

Post by heartbone »

The first ScreenOutput() or SpriteOutput() generated display of any program does not show.
PB 5.43 x64 UBUNTU 16.04 LTS

Save the source code and any 640x480 .jpg into the same folder.
If you use http://www.bealecorner.com/trv900/testpat/MVC00002.JPG then the name is already setup in the source code.

The problem is that the first generated display does not show.
Swap move the 4 sections which are delimited by and include the lines ; VVVVVVVV and ; ^^^^^^^^^^.
Only the first one of the four sections in the source will not work.
(If you use the Esc key to exit the screen, then don't hold it down because there's no code to wait for the key release.)

Can anyone figure out a way to make the first built display show?
Perhaps another way to think of it, does anyone know what gets triggered to make the subsequent calls work properly?

As usual the program works fine in Windows®.

Code: Select all

UseJPEGImageDecoder() 

Procedure UCLOWIN()
; Stay here until Esc key is depressed or window close icon is selected
   BYEBYE= 0
   Repeat
      RELEASE= ElapsedMilliseconds()+ 20
      Repeat
         X= WindowEvent() : If X = #PB_Event_CloseWindow : BYEBYE+ 1 : EndIf   
      Until X = 0 
      ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Escape) : BYEBYE+ 1 : EndIf 
      If ElapsedMilliseconds() < RELEASE
         Repeat : Delay(2) : Until ElapsedMilliseconds() > RELEASE
      EndIf
   Until BYEBYE  
EndProcedure

Z1= InitSprite()
Z2= OpenWindow(0,0,0,800,600,"PROGRAM",#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget)
Z3= OpenWindowedScreen(WindowID(0),0,0,800,600,#True,0,0)
Z4= InitKeyboard()
Z5= CreateSprite(0,800,600)

If (Z1<>0 And Z2<>0 And Z3<>0 And Z4<>0 And Z5<>0)
   CatchImage(1,?BITMAP) 

   FlipBuffers()  

; VVVVVVVVVVVVVVVVVVVVVVVV SPRITEOUTPUT() START VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
   StartDrawing(SpriteOutput(0))
   Box(0,0,800,600,RGB(0,63,0)) 
   DrawText(50,30,"SPRITE OUT GREEN")
   DrawImage(ImageID(1),80,60) 
   StopDrawing()
   DisplaySprite(0,0,0)
   FlipBuffers()  
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   UCLOWIN()
   Delay(50)

; VVVVVVVVVVVVVVVVVVVVVVVV SCREENOUTPUT() START VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
   StartDrawing(ScreenOutput())    
   Box(0,0,800,600,RGB(0,0,63)) 
   DrawText(50,30,"SCREEN OUT BLUE")
   DrawImage(ImageID(1),80,60) 
   StopDrawing()
   FlipBuffers()   
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   UCLOWIN()
   Delay(50)

; VVVVVVVVVVVVVVVVVVVVVVVV SCREENOUTPUT() START VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
   StartDrawing(ScreenOutput())    
   Box(0,0,800,600,RGB(63,0,0)) 
   DrawText(50,30,"SCREEN OUT RED")
   DrawImage(ImageID(1),80,60) 
   StopDrawing()
   FlipBuffers()   
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   UCLOWIN()
   Delay(50)

; VVVVVVVVVVVVVVVVVVVVVVVV SPRITEOUTPUT() START VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
   StartDrawing(SpriteOutput(0))
   Box(0,0,800,600,RGB(63,63,63)) 
   DrawText(50,30,"SPRITE OUT GRAY")
   DrawImage(ImageID(1),80,60) 
   StopDrawing()
   DisplaySprite(0,0,0)
   FlipBuffers()  
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   UCLOWIN()

EndIf 

DataSection
BITMAP: : IncludeBinary "MVC00002.JPG"
; http://www.bealecorner.com/trv900/testpat/MVC00002.JPG
EndDataSection   
If you place a UCLOWIN() call immediately after the FlipBuffers() call on line 28, then it works better.
But if you don't have the FlipBuffers() call there immediately preceding that inserted UCLOWIN() call, then things get decidedly ugly.
Keep it BASIC.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Initial graphics screen does not display.

Post by heartbone »

If in the Compiler Options one changes the Library Subsystem to gtk2, then it gets even worse.
It blows up.
Keep it BASIC.
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: Initial graphics screen does not display.

Post by BasicallyPure »

Hi,
I got it to work on my computer by adding the code shown below.
It seems to be 100% working for me with the extra code.

Code: Select all

If (Z1<>0 And Z2<>0 And Z3<>0 And Z4<>0 And Z5<>0)
   CatchImage(1,?BITMAP)
   
   ; ************** added this code ************
   While WindowEvent() : Wend
   FlipBuffers()
   ClearScreen(0)
   ; *******************************************
   
; VVVVVVVVVVVVVVVVVVVVVVVV SPRITEOUTPUT() START VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Initial graphics screen does not display.

Post by infratec »

Hi,

I can not test it, because at the moment I only have remote virtual linux machines,
but I would try to comment two FlipBuffers():

Line 28 and 37

Bernd
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Initial graphics screen does not display.

Post by heartbone »

BasicallyPure wrote:Hi,
I got it to work on my computer by adding the code shown below.
It seems to be 100% working for me with the extra code.

Code: Select all

If (Z1<>0 And Z2<>0 And Z3<>0 And Z4<>0 And Z5<>0)
   CatchImage(1,?BITMAP)
   
   ; ************** added this code ************
   While WindowEvent() : Wend
   FlipBuffers()
   ClearScreen(0)
   ; *******************************************
   
; VVVVVVVVVVVVVVVVVVVVVVVV SPRITEOUTPUT() START VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Yes indeed BasicallyPure, that fix seems to work here as well.
Thank you for figuring out an initialization process.
IMO you have earned a PB Linux hacker award for August!

Image

The same code still blows up with an invalid memory access on the first StopDrawing() statement when the gtk2 Library Subsystem is used.
Is that behavior a bug or not?
I'll leave that up to you.
Keep it BASIC.
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Initial graphics screen does not display.

Post by Fred »

You need to structure your code in another way, when using a window an event loop is always required to not block the app. Better use AddWindowTimer() instead of Delay() to display you frame at regular interval.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: Initial graphics screen does not display.

Post by heartbone »

Fred wrote:You need to structure your code in another way, when using a window an event loop is always required to not block the app. Better use AddWindowTimer() instead of Delay() to display you frame at regular interval.
Nope Fred, that is an incorrect analysis of this situation.
The only Delay() statements in the code were used to allow the user to get off the Esc key before the next display is generated.

There is most definitely a problem with the compiler, not the code structure.
BasicallyPure has discovered a fix, but a proper internal solution would be preferred.
Because we have a fix, it is not a high priority.
Also, removing this thread from the Linux bug reports section to the coding questions sections was a really bad move on a couple of fundamental levels.
Keep it BASIC.
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: Initial graphics screen does not display.

Post by BasicallyPure »

Hi,
heartbone wrote:The only Delay() statements in the code were used to allow the user to get off the Esc key before the next display is generated.
There is a way to simplify that by using KeyboardReleased(#PB_Key_Escape) in place of KeyboardPushed(#PB_Key_Escape).
It gets rid of the delay however I don't think it has anything to do with the problem.

Code: Select all

Procedure UCLOWIN()
; Stay here until Esc key is depressed or window close icon is selected
   BYEBYE= 0
   Repeat
      Repeat
         X= WindowEvent() : If X = #PB_Event_CloseWindow : BYEBYE+ 1 : EndIf   
      Until X = 0
      ExamineKeyboard()
      If KeyboardReleased(#PB_Key_Escape) : BYEBYE+ 1 : EndIf
   Until BYEBYE 
EndProcedure
I do not totally understand Fred's comment.
Was he trying to say the screen must be continuously updated even if the content does not change?
It looks like you already have the required event loop for handling all windows events.
heartbone wrote:The same code still blows up with an invalid memory access on the first StopDrawing() statement when the gtk2 Library Subsystem is used.
confirmed.
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
Post Reply