I'm having various problems handling lost devices in SlimDX (I only started with it yesterday, moving from XNA).
My problems occur when I hit Ctrl-Alt-Delete in Vista, which causes the debug runtimes to spit out the following:
Direct3D9: (ERROR) :Lost due to display uniqueness change
D3D9 Helper: IDirect3DDevice9::Present failed: D3DERR_DEVICELOST
A first chance exception of type 'SlimDX.Direct3D9.Direct3D9Exception' occurred in SlimDX.dll
An unhandled exception of type 'SlimDX.Direct3D9.Direct3D9Exception' occurred in SlimDX.dll
Additional information: D3DERR_DEVICELOST: Device lost (-2005530520)
Which breaks on Present() in my drawScene() call.
Relevant code snippets below, the observant among you may notice it's DirectX 9.0c: A Shader Apporach, translated into C#.
public virtual void run()
{
long prevTimeStamp = timer.ElapsedMilliseconds;
while (window.Created)
{
if (!isDeviceLost())
{
long currentTimeStamp = 0;
currentTimeStamp = timer.ElapsedMilliseconds;
float dt = (currentTimeStamp - prevTimeStamp) / 1000.0f;
updateScene(dt);
drawScene();
prevTimeStamp = currentTimeStamp;
}
Application.DoEvents();
}
}
public bool isDeviceLost()
{
Result result = d3dDevice.TestCooperativeLevel();
if (result == ResultCode.DeviceLost)
{
onLostDevice();
return true;
}
else if (result == ResultCode.DriverInternalError)
{
MessageBox.Show("Internal Driver Error... Exiting");
Application.Exit();
return true;
}
else if (result == ResultCode.DeviceNotReset)
{
d3dDevice.Reset(presentParameters);
onResetDevice();
return false;
}
else
{
return false;
}
}
[Edited by - adt7 on August 9, 2009 5:12:15 PM]