Flip( True ) hangs the application

BlitzMax Forums/BlitzMax Programming/Flip( True ) hangs the application

Kryzon(Posted 2014) [#1]
I have a windowed, realtime 3D application that I'm updating based on timer ticks, with 30 FPS.

I just noticed that the application hangs when I use Flip( True ) after rendering.
There's no input being polled, and if I hit ALT+F4 to terminate the application, it will only close when I focus on another application and then back mine.

If I use Flip() with no VSync it works fine, although it causes a very noticeable tearing.
Is there a way to keep VSync on, but not hang the program?


Kryzon(Posted 2014) [#2]
I have apparently bypassed the problem by changing the main loop from being event-based (using a Repeat...Forever loop with WaitSystem() inside, and the application updating through event hooks) to being poll-based (a Repeat...Forever loop with WaitTimer() inside and manually calling the update method instead of using event hooks).

That is odd.


Chapman7(Posted 2014) [#3]
I tried to recreate your error:
Graphics 800,600


timer=CreateTimer( 30 )


Local FPS:Int
Local FPSFrames:Int
Local FPSTime:Int

While Not AppTerminate()
	WaitEvent()
	Select EventID()
		Case EVENT_TIMERTICK
			If MilliSecs() - FPSTime > 1000 Then
				FPS = FPSFrames
				FPSFrames = 0
				FPSTime = MilliSecs()
			Else
				FPSFrames = FPSFrames + 1
			EndIf
			
			Cls
			DrawText(FPS, 0, 0)
			Flip(True)

	EndSelect
Wend

But it works fine for me.

If you want to update using TimerTicks but still want VSync, you could do
Timer = CreateTimer( (DesktopHertz() Or 60) )

If that doesn't work how you want, let me know what I have to change to recreate the problem

EDIT: WaitSystem() instead of WaitEvent() causes issues for me, but it doesn't completely hang the application


Kryzon(Posted 2014) [#4]
The code that hanged the application and input was performed with hooks, so all that code inside the EVENT_TIMERTICK block could be called like this:



Then try moving the window around by click-dragging the title bar, then alt-tabbing to other program and then returning.
I did this with the program above and it's working -- so I can't prove my point -- but in my original program, setting Flip( True ) would hang the application if I did those things.
Switching to an open loop like your example solved the problem (that is, manually invoking the update methods, instead of relying on hooks) and allowed me to still use Flip( True ) which is essential for smooth motion graphics.

EDIT: And thank you for testing.


Mr. Goober(Posted 2014) [#5]
I think that this problem is related to the refresh rate of your monitor. Flip (1) will wait for the next vertical blank. Flip also behaves differently if you use CreateGraphics() rather than Graphics().