Possible Bug - Buffers not working correctly?

Blitz3D Forums/Blitz3D Programming/Possible Bug - Buffers not working correctly?

Serpent(Posted 2009) [#1]
Hello,
Basically, it seems that whenever I try to draw graphics or text to the BackBuffer, it draws it to the front buffer instead.

Running a simple snippet of code as a test, my suspicions seem to be confirmed.

Graphics 800,600,32,2

SetBuffer FrontBuffer()
Print "Front"

SetBuffer BackBuffer()
Print "Back"

While Not KeyHit(1)
	WaitKey
	Flip
Wend
End



This should theoretically display 'front' when one buffer is displayed, and 'back' when the other is brought to the front. Every time you press a key, it should swap between displaying 'Front' and 'Back'.

When I run this, both 'Front' and 'Back' appear at the same time (as if both times the text was drawn to the front...), and when I press a key (calling the flip command) nothing happens.


Please let me know if I've got something mixed up or don't understand how buffering works correctly, but it appears that, no matter what I try, graphics and text are drawn to the Front Buffer.


Serpent(Posted 2009) [#2]
Looking further into this, I wondered if perhaps it took a while to switch buffers. I tried inserting long delays in various locations in the following example:

Graphics 800,600,32,2
SetBuffer FrontBuffer()
Text 0,0, "Front"
SetBuffer BackBuffer()
Delay 100
Text 0,20,"Back"
While Not KeyHit(1)
WaitKey
Flip
Wend
End


However, the only one that had an effect was the one after changing the buffer to the backbuffer. Then, the text 'Back' is not displayed at the start. However, the flip command still does nothing whatsoever here.

Tweaking the length of the delay, it seems that the minimum amount of time that can be used to have the text 'Back' not drawn to the Front Buffer is around 60 milliseconds, and sometimes it works whereas other times it doesn't (indicating that changing to a different buffer is done asynchronously or something)


Should have put this info in my last post:
B3D Version: 1.103
OS: Windows Vista Home Premium (32-bit) SP2
Graphics Card: nVidia GeForce 9600 GS
nVidia Driver Version: 195.55


Floyd(Posted 2009) [#3]
There are at least three things to consider.

Print always draws to the front (visible) buffer. You should use Text, which is a graphics command.

Another problem is that there really is no back buffer in windowed mode. In fullscreen you have a true back buffer in addition to the front buffer. Flip just changes which of these is used for the screen display. That is impossible in windowed mode because your program is not in charge of the entire screen. Instead, Blitz tries to fake this functionality. It maintains a buffer for its own use, drawing to this rather than a real back buffer. The Flip command then copies from this buffer to the on-screen window.

Finally, keep in mind that immediately after a Flip the contents of the back buffer, which used to be the front buffer, are undefined. They may be the old front content, undisturbed. Or the memory might get cleared. Or it might be corrupted in some way, perhaps being used as some kind "scratchpad" memory. This is determined by the graphics card and driver. If you draw to both buffers and simply flip between them you get unpredictable results. What works for you may be quite different on another computer.


Serpent(Posted 2009) [#4]
Thanks for this. Everyone does work perfectly in fullscreen mode. Can someone please remove this thread?


Floyd(Posted 2009) [#5]
There's enough information here that it is worth keeping. I have moved it from the Bug Reports.