Thursday, April 26, 2007

XNA: GraphicsDevice.DeviceLost Doesn't Fire

What is device loss?
Device loss occurs when Windows takes the graphics device from an application, preventing the application from rendering. The easiest way to trigger device loss is to lock your work station. To render the locked workstation screen, Windows will steal the graphics device. When the application gets the device back it must recreate the graphics content that is no longer valid.

GraphicsDevice.DeviceLost Event
This event fires when GraphicsDevice.Present() is called on a lost device. In most cases, including the "Game" class in XNA, this event will never fire because the render loop simply won't call Present()if the device is lost. The render loop might look something like this:

if (device.GraphicsDeviceStatus == GraphicDeviceStatus.Lost)
{
device.Reset();
}
if (device.GraphicsDeviceStatus == GraphicDeviceStatus.Normal)
{

device.Present();
}

I suppose the device could be lost between checking the GraphicsDeviceStatus and calling Present() then DeviceLost would fire, but that is generally unlikely.

Labels:

0 Comments:

Post a Comment

<< Home