VChelaru

VChelaru

  • NA
  • 1
  • 0

After two alt tabs, full screen DX app constantly sending D3DERR_DEVLOST exception.

Mar 25 2005 4:52 PM
This problem is actually in a larger appliation. As I was trying to isolate it, I got off track, and finally, by shrinking the project down, the problem came back. So I think this is the root of everything. This small program is designed to create a full-screen app, hide the mouse, and continually refresh the screen to black. When I alt-tab once, then go back in, everything's fine. However, once I go back in a 2nd time from an Alt-Tab I get the D3DERR_DEVLOST exception. The section that prints out the error in a MessageBox under the FindDevice method gets looped over and over. That is, the Device is constantly lost, and never NotReset. I can't figure out what's causing this problem, since I'm not declaring any textures or VBs. Here's the code: [code] using System; using System.Drawing; using System.Windows.Forms; using Microsoft.DirectX.Direct3D; using D3D = Microsoft.DirectX.Direct3D; using Microsoft.DirectX; namespace GameName { public class GameForm : Form { internal Microsoft.DirectX.Direct3D.Device device = null; public bool LostDevice; PresentParameters presentParams = new PresentParameters(); public GameForm() { Size tempSize = SystemInformation.PrimaryMonitorSize; this.ClientSize = new System.Drawing.Size(tempSize.Width,tempSize.Height); System.Windows.Forms.Cursor.Hide(); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; presentParams.Windowed= false; presentParams.SwapEffect = SwapEffect.Discard; // Discard the frames presentParams.EnableAutoDepthStencil = true; // Turn off a Depth stencil presentParams.AutoDepthStencilFormat = DepthFormat.D16; // And the stencil format presentParams.BackBufferFormat = Microsoft.DirectX.Direct3D.Format.R5G6B5; presentParams.BackBufferHeight = tempSize.Height; presentParams.BackBufferWidth = tempSize.Width; presentParams.BackBufferCount = 2; presentParams.FullScreenRefreshRateInHz = 75; presentParams.DeviceWindow = this; presentParams.PresentationInterval = PresentInterval.Immediate; device = new Microsoft.DirectX.Direct3D.Device(0, D3D.DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing , presentParams); //Create a device } static void Main() { GameForm frm = new GameForm(); frm.Show(); while(frm.Created) { if(frm.LostDevice) frm.FindDevice(); if(!frm.LostDevice) { try { frm.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); frm.device.BeginScene(); } catch(Microsoft.DirectX.Direct3D.InvalidCallException) { frm.LostDevice = true; } } try { //End the scene frm.device.EndScene(); frm.device.Present(); } catch { frm.LostDevice = true; } Application.DoEvents(); } } public void FindDevice() { int checkCooperationLevelResult; while(LostDevice) { device.CheckCooperativeLevel(out checkCooperationLevelResult); if(checkCooperationLevelResult == (int)ResultCode.DeviceLost) { try{ System.Windows.Forms.Application.DoEvents();} catch(Microsoft.DirectX.DirectXException e) { System.Windows.Forms.MessageBox.Show("We get this problem after 2 resumes from Alt-Tab \n" + e.ToString()); } } else if(checkCooperationLevelResult == (int)ResultCode.DeviceNotReset) { try { device.Reset(presentParams); LostDevice = false; } catch (Microsoft.DirectX.Direct3D.InvalidCallException) { LostDevice = true; break; } } } } } } [/code] And here is my error that I get: http://www.flatredball.com/content/myError.png If it matters, I'm using the latest XP, ATI Radeon 9600 SE card, and have a dual display. Any help would be greatly appreciated. I've spent quite some time on this problem. --Vic--