Unhandled Exception in d3d7graphis.bmx - new info

BlitzMax Forums/BlitzMax Programming/Unhandled Exception in d3d7graphis.bmx - new info

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here is yet another test program:

'SetGraphicsDriver GLMax2DDriver()

Global App:Application = Application.Create("Fruit Sliders", 800, 600, 0, True)

Image:TImage = CreateImage(32, 32)
DrawImage(Image, 0, 0)

Repeat  

	If KeyHit(KEY_F) 
		App.ToggleFullscreen()
		DebugLog("State : " + App.Windowed)
	EndIf

	Flip True

Until KeyHit(KEY_ESCAPE)


Type Application

	Field Name$
	
	Field Width%
	Field Height%
	Field Depth%

	Field Window:TGadget
	Field Canvas:TGadget
	Field Panel:TGadget
	
	Field TG_FullScreen:TGraphics
	Field TG_Canvas:TGraphics
	
	Field Windowed%


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This function creates the game window, and sets up the graphics objects for windowed and fullscreen modes. 
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Function Create:Application(AppName$, AppWidth%, AppHeight%, AppDepth%=0, Fullscreen%=False)
	
			Local X%, Y%	
			Local App:Application
			
			'SetGraphicsDriver GLMax2DDriver()
			
			' Create new application.
				App = New Application 				
									
			' Store application settings.
				App.Name$  = AppName$
				App.Width  = AppWidth
				App.Height = AppHeight	
				App.Depth  = AppDepth
				
			' If Depth is 0, try to find a suitable fullscreen bit depth.
			
				If App.Depth = 0
				
					App.Depth = 16
					If GraphicsModeExists(App.Width, App.Height, 24) Then App.Depth = 24
					If GraphicsModeExists(App.Width, App.Height, 32) Then App.Depth = 32
				
				EndIf		
					
			' Create a window in the center of the screen.
		
				X = GadgetWidth(Desktop())/2  - App.Width/2
				Y = GadgetHeight(Desktop())/2 - App.Height/2

				App.Window = CreateWindow(App.Name$, X, Y, App.Width, App.Height, Null, WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_CLIENTCOORDS|WINDOW_HIDDEN)
				SetMinWindowSize(App.Window, GadgetWidth(App.Window), GadgetHeight(App.Window))
								
			' Create a panel in the window, drawn behind the canvas, which fills the empty space around the gameplay area when the window is maximized.
				App.Panel = CreatePanel(0, 0, App.Width, App.Height, App.Window)
				SetPanelColor(App.Panel, 0, 0, 0)
				SetGadgetLayout(App.Panel, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED)
		
			' Create a canvas.
				App.Canvas = CreateCanvas(ClientWidth(App.Window)/2-App.Width/2, ClientHeight(App.Window)/2-App.Height/2, App.Width, App.Height, App.Panel)
				App.TG_Canvas = CanvasGraphics(App.Canvas)
								
			' Set game to windowed or fullscreen as desired.
				Select Fullscreen
					Case False App.SetWindowed()
					Case True  App.SetFullscreen()
				End Select
			
			' Return new application instance.
				Return App
												
		End Function
		

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method toggles between fullscreen or windowed mode, choosing the opposite of whichever is currently enabled.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	
		Method ToggleFullscreen()
		
			Select Windowed
				Case False SetWindowed()
				Case True  SetFullscreen()
			End Select
			
		End Method

	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method puts the application in windowed mode.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------
		
		Method SetWindowed()
				
				SetGraphics TG_Canvas
				Windowed = True
				
				ShowGadget Window
				ActivateGadget Canvas
				
			' Canvas must be activated for input or else game will make user click on canvas before any polled keyboard input is returned.
				EnablePolledInput()			
													
		End Method	


	' -------------------------------------------------------------------------------------------------------------------------------------------------------
	' This method sets the application to fullscreen mode, unless no fullscreen mode in the desired resolution exists.
	' -------------------------------------------------------------------------------------------------------------------------------------------------------

		Method SetFullscreen()
			
			Local G:TGraphics
											
			If TG_Fullscreen = Null Then TG_Fullscreen = CreateGraphics(Width, Height, Depth, 0, 0)
			Windowed = False

			' If the switch to fullscreen failed, put us back in windowed mode. 
				If TG_Fullscreen = Null 
					RuntimeError("Error in Application.SetFullscreen() : Could not set full screen mode!") 
					'SetWindowed()
				Else
					HideGadget Window
					SetGraphics TG_Fullscreen	
					EnablePolledInput()	
				EndIf
					
		End Method

				
End Type						
		
		

' -----------------------------------------------------------------------------------------------------------------------------------------------------------
' This function overrides the standard RuntimeError function which does not work properly.  Assert also does not work.
' -----------------------------------------------------------------------------------------------------------------------------------------------------------

	Function RuntimeError(Error$)
		EndGraphics
		Notify(Error$, True)
		End
	End Function



This version attempts to create a canvas when the window is created, then when switching to fullscreen for the first time, it uses CreateGraphics() to create a fullscreen graphics context. From there on, it attempts to switch between the two contexts with SetGraphics, and never tries to recreate either.

This version fails the worst though. In DirectX, it crashes when attempting to switch back to windowed from fullscreen, giving "createsurface failed" as the error. (If you alter the app to attempt to run in windowed mode first, it will switch from canvas to fullscreen but not back.) In OpenGL, things are even weirder than before. Not only do you have the flashing start menu bar at the bottom of the screen, but after you switch back to windowed mode, if you press F again, nothing happens! You have to actually click the window button on the task bar to get it to go back into fullscreen mode. And once there, the formerly flashing start menu bar in fullscreen now has flashing streaks of black over it, as if Flip True is no longer waiting for the vertical refresh.