Lost Graphics When Alt+Tab in FullScreen

BlitzMax Forums/BlitzMax Programming/Lost Graphics When Alt+Tab in FullScreen

Blitzogger(Posted 2011) [#1]
I am trying to create a game that allows to to switch between full screen and windowed with Alt+Enter. However when the game is switch back, it generates a lost graphics error and exits. Here is my graphics switching code:
If KeyDown(Key_LAlt) And KeyDown(Key_Enter) Or KeyDown(Key_RAlt) And KeyDown(Key_Enter)
			' and the game is windowed
			If FullScreenFlag=0
				' attempt to open a full screen window
				If Not Graphics(800,600,32)
					' if a fullscreen window couldn't be opened, display an error message
					Notify "Failed to switch to fullscreen"
					'and terminate
					End
				EndIf
				' set fullscreen to true
				FullScreenFlag=1
				' otherwise the game is in fullscreen
				Else
				' attempt to open a windowed game
				If Not Graphics(800,600,0)
					' if a window game couldn't be opened, display an error message
					Notify "Failed to switch to game window"
					'and terminate
					End
				EndIf
				' set fullscreen to true
				FullScreenFlag=0
			EndIf
		EndIf

Any assistance in this matter would be greatly appreciated.

Sincerely,

Blitzogger


col(Posted 2011) [#2]
Works fine here in OpenGL and DirectX.

I made a tiny program to test it with


Last edited 2011


therevills(Posted 2011) [#3]
What version of BlitzMax are you using? I recall a very(!) old version having this issue.


ima747(Posted 2011) [#4]
If you're up to date with your bmax, what about your graphics drivers, and what vid card are you using? Are you using dx or opengl, and have you tried the other?

Sounds like a context is getting abandoned, or dieing in the transition for some reason which would imply it's probably not at your level, but up stream in bmax, or opengl/dx, or the drivers, or the card...


Grey Alien(Posted 2011) [#5]
I have a similar bomb out to this with my games on my XP PC, but only since I changed graphics cards. The same games are fine on Win7 and other PCs. Been meaning to rewrite the code so that it if detects loss of focus it will remake the graphics when focus is regained.


Kryzon(Posted 2011) [#6]
Not that this would change anything (simple logic optimization), but you don't need to check for Enter twice:
'Check both ALTs at the same time.
If KeyDown(Key_Enter) And (KeyDown(Key_LAlt) Or KeyDown(Key_RAlt)) Then



Blitzogger(Posted 2011) [#7]
I'm testing on a IBM Thinkpad T22 running Windows XP SP2 machine, with a S3 Savage IX Video Card, DirectX 9.0c and BlitzMax 1.42. I don't have another machine to test if it still craps out, it does on my machine. Any assistance would be greatly appreciated.

Sincerely,

Blitzogger


beanage(Posted 2011) [#8]
Afaik, the graphcs context gets recreated when you tab up. try GLShareContexts() before initializing youre graphics:

SetGraphicsDriver(GLMax2DGraphicsDriver())
GLShareContexts()
Graphics(800,600,0)

Repeat
  Cls
  ..
  Flip
Until AppTerminate()


Last edited 2011