[SlimDX] Device Lost Handling

Started by
1 comment, last by Stormtrooper 15 years, 9 months ago
I'm trying to get my program to handle lost devices(following the Sample as an example) I have this code in the game loop:

            if (_device.Present() == ResultCode.DeviceLost)
                _deviceLost = true;
Now when the device is lost, it throws an exception and the program stops running. In the Samples, it does not throw an exception and everything keeps going on its marry way. How do I stop it from throwing an exception and keep going?
Advertisement
SlimDX is automatically set to throw exceptions on any failure result. There are a few ways to customize this behavior. First, you could set the Configuration.ThrowOnError property to false, and then none of the methods will throw exceptions, but will instead return result codes for you to test. This is generally not recommended, since it's very difficult and tedious to be sure you test the result of each method call.

The second way would be to customize the set of results that will trigger an exception. This is the method that the samples use. Simply add a result watch connecting the result code with the action you wish to take. For example:

Configuration.AddResultWatch(ResultCode.DeviceLost, ResultWatchFlags.AlwaysIgnore);Configuration.AddResultWatch(ResultCode.WasStillDrawing, ResultWatchFlags.AlwaysIgnore);
Mike Popoloski | Journal | SlimDX
It works. Thanks!

This topic is closed to new replies.

Advertisement