Problem with primary device + alt tab

BlitzMax Forums/BlitzMax Programming/Problem with primary device + alt tab

Hi :)

I have a problem with a primary device and alt tab ?
when a made a ALT TAB the program crash at this line

"PrimaryDevice.device.DrawPrimitive(RenderType,D...."

Is there a way to stop the rendering/freeze rendering
to prevent ALT TAB crash ?

      If (DX) Then
        TD3D7Max2DDriver(_max2dDriver).SetActiveFrame(DXFrame)
		PrimaryDevice.Device.EndScene() 
        PrimaryDevice.device.DrawPrimitive(RenderType,D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1,xyuv,segs,0)
		PrimaryDevice.Device.BeginScene()
      ElseIf Line = True
         GLEnd()               
      EndIf


I have try to find DX doc about this and there is a command

DeviceLost

But i don't know how use it ?

// On ajoute une variable locale
private bool isDeviceLost = false;

// Aprés l'initialisation du device Direct3D
device.DeviceLost += new EventHandler(OnLostDevice);

// Fonction appelée lors de l'interception de l'évènement "DeviceLost"
private void OnLostDevice(object sender, EventArgs e)
{
	// On initialise la variable locale à TRUE
    isDeviceLost = true;
    
    // Traitement de l'évènement 
}


Try checking this variable..

TD3D7Max2DDriver(_max2dDriver).IsLost before attempting to play with the PrimaryDevice


Doug Stastny

Many thanks budman !!! it work !

Here is the code

		If TD3D7Max2DDriver(_max2dDriver).IsLost=False
	        TD3D7Max2DDriver(_max2dDriver).SetActiveFrame(DXFrame)
			PrimaryDevice.Device.EndScene() 
	        PrimaryDevice.device.DrawPrimitive(RenderType,D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1,xyuv,segs,0)
			PrimaryDevice.Device.BeginScene()
		EndIf


Great glad to have helped.

Comment on your code. DrawPrimative must be between BeginScene, EndScene.

The 2d driver manages the Scene State so you shouldnt need EndScene.. BeginScene. I am suprised it works. Some cards might not though.


If TD3D7Max2DDriver(_max2dDriver).IsLost=False
	        TD3D7Max2DDriver(_max2dDriver).SetActiveFrame(DXFrame)
' not needed			PrimaryDevice.Device.EndScene() 
	        PrimaryDevice.device.DrawPrimitive(RenderType,D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1,xyuv,segs,0)
' not needed			PrimaryDevice.Device.BeginScene()
		EndIf



Doug Stastny