CreateGraphics error handling

BlitzMax Forums/BlitzMax Programming/CreateGraphics error handling

Chapman7(Posted 2014) [#1]
Will this do the trick:
SetGraphicsDriver( GLMax2DDriver() )
If Not Graphics( 800, 600, 0, (DesktopHertz() Or 60) ) Then
	Notify( "Failed to initialize graphics", True )
	End
EndIf

Or does somebody have a better way?
Also does SetGraphicsDriver ever have issues? (Should I do the same for it?)


Derron(Posted 2014) [#2]
I have this:

Select renderer
	?Win32
	Case RENDERER_DIRECTX7
			SetGraphicsDriver D3D7Max2DDriver()
	Case RENDERER_DIRECTX9
			SetGraphicsDriver D3D9Max2DDriver()
	?
	?Linux
'	Case RENDERER_BUFFEREDOPENGL
'	SetGraphicsDriver BufferedGLMax2DDriver()
	?
	Default SetGraphicsDriver GLMax2DDriver()
EndSelect

_g = Graphics(realWidth, realHeight, colorDepth*fullScreen, hertz, flags)

?Win32
'on win32 we could try to fallback to DX7
If not _g and renderer <> RENDERER_DIRECTX7
	Throw "Graphics initiation error! The game will try to open in DirectX 7 mode."
	SetGraphicsDriver D3D7Max2DDriver()
	_g = Graphics(realWidth, realHeight, colorDepth*fullScreen, hertz, flags)
endif
'or to OpenGL
If not _g and renderer <> RENDERER_OPENGL
	Throw "Graphics initiation error! The game will try to open in OpenGL mode."
	SetGraphicsDriver GLMax2DDriver()
	_g = Graphics(realWidth, realHeight, colorDepth*fullScreen, hertz, flags)
endif
?
if not _g then Throw "Graphics initiation error! no render engine available."



"renderer" is an int-property read from an xml config, so adjust properly.


Yours will do too. But I think you could use "Throw" instead of "Notify" because you surely want your app to exit then (with no proper useable graphics mode).


bye
Ron


Chapman7(Posted 2014) [#3]
Thanks man! Do you think SetGraphicsDriver will ever have problems? Should I do something like:
SetGraphicsDriver GLMax2DDriver()
If GetGraphicsDriver <> GLMax2DDriver() Then
     'Do Stuff
EndIf