Flip() bug

Archives Forums/BlitzMax Bug Reports/Flip() bug

JoshK(Posted 2009) [#1]
Example of the bug. This could be driver-specific, but I am testing this on an NVidia GEForce 8800:
Framework brl.GLGraphics
Import brl.standardio

Graphics(800,600,32)

While Not KeyHit(KEY_ESCAPE)
	If KeyHit(KEY_F1) Flip 1
	glClear COLOR_BUFFER_BIT
	GLDrawText "FPS: "+FPS(),0,0
	GLDrawText "1. Alt-Tab to Desktop",0,15
	GLDrawText "2. Alt-Tab back to this app",0,30
	GLDrawText "3. Notice that FPS has fallen to 60",0,45
	GLDrawText "4. Press F1 to fix FPS bug",0,60	
	Flip(0)
Wend

Function FPS#()
	Global last:Int
	Local time:Int
	time=MilliSecs()
	Local elapsed:Float=time-last
	last=time
	elapsed=Max(elapsed,1)
	Return 1.0/elapsed*1000.0
EndFunction


I looked in the source and found the cause is that the swap interval only gets changed when the sync variable changes:
	static int _sync=-1;

	if( !_currentContext ) return;
	
	sync=sync ? 1 : 0;
	if( sync!=_sync ){
		_sync=sync;
		_setSwapInterval( _sync );
	}

	SwapBuffers( _currentContext->hdc );



marksibly(Posted 2009) [#2]
Hi,

Please describe briefly what the the problem actually *is*!

'Example of the bug...' followed by a bunch of source code isn't very useful...


plash(Posted 2009) [#3]
'Example of the bug...' followed by a bunch of source code isn't very useful...
He does that a lot..

.. Anyhow, I suspect this has something to do with some value operation skipping because of a loss of focus on the graphics window.


JoshK(Posted 2009) [#4]
The program starts in fullscreen mode and runs at about 1000 FPS. Flip(0) is used the entire time.

The user presses Alt+Tab and goes to another program, so the desktop is shown again.

When the user goes back to the fullscreen BlitzMax program, the vertical sync is locked at 60 FPS even though Flip(0) is used. Pressing F1 to flip the buffer once with a swap interval of causes Flip(0) to once again run at 1000 FPS.

It's easiest if you just follow the directions the program writes onscreen, and you'll see what I mean.

I guess the driver internally sets the swap interval back to 1 when the user goes to the desktop, and the BlitzMax application doesn't set it back to zero until the BlitzMax variable is different from the last time Flip() was called.


Hujiklo(Posted 2010) [#5]
Chumping nora! This little tw*t had me screaming at the monitor!!!
Glad somebody gave me a clue here... This and that damn mousehit() bug have ruined my weekend :(


marksibly(Posted 2010) [#6]
Hi,

Guess it wouldn't hurt to always force the swap interval...and this is just on Windows, right?