Device Lost Issues in SlimDX

Started by
4 comments, last by JoshuaBaker 12 years, 1 month ago
Iv got some VERY simple code here...

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using SlimDX;
using SlimDX.Direct3D9;
using SlimDX.Windows;
namespace MiniTri {
static class Program {
[STAThread]
static void Main() {
Direct3D direct3d = new Direct3D();

RenderForm form = new RenderForm("DX9 Test");
form.ClientSize = new Size(800, 600);
form.TopMost = true;
form.FormBorderStyle = FormBorderStyle.None;
PresentParameters presentparameters = new PresentParameters();
presentparameters.BackBufferWidth = 800;
presentparameters.BackBufferHeight = 600;
presentparameters.Windowed = false;
presentparameters.BackBufferFormat = Format.X8R8G8B8;
Device device = new Device(direct3d, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, presentparameters);
MessagePump.Run(form, () => {
device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
device.Present();
});

foreach (var item in ObjectTable.Objects)
item.Dispose();
}
}
}


It should simply make a fullscreen DX9 application. Yet on my PC i get continual device Lost errors. Iv stripped out everything to the bare minimum and still it crashes with device lost. I get the feeling it might be my dual monitors, as the code seemed ok on my laptop, but i'm not sure how to deal with that.
Advertisement
You need to handle the device lost exception, and reset the device after freeing up all resources that aren't in the managed pool. You can then recreate those resources again after the reset.

Something like what's done in this sample code (search for "lost") http://code.google.com/p/slimdx/source/browse/trunk/samples/SampleFramework/Sample.cs
Thanks!

I had tried that before, but i likely was handling it wrong. Using the format from the sample it seems to work. Any insight into why its ok on a single monitor? My laptop handled it just fine.
One obvious possibility is that on Vista/7 less things will cause you to lose the device than under XP. Are both computers running the same OS?

To force a lost device on Vista/7 the simplest option is to press control-alt-del and then cancel it.

It doesn't really matter though - all DX9 programs need to be able to handle a lost device at any time. You can only avoid that requirement by dropping XP support and using D3D9Ex or D3D11.
Both run Win7. I knew i would lose the device on a at tab or anythign that would minimize the fullscreen window so i expected that. This is getting a device lost immediately after running the program, which was odd. At times i could actually see things render for a frame, then it would immediately get device lost.
So while my code TECHNICALLY works, its working in a bad way. The very first time i call present, i WILL get a device lost on my two monitor setup. This seems like an issue as no matter what, my first frame is always lost and i will have to reset everything...which can't be a good thing in a larger application. there must be something odd going on here.

This topic is closed to new replies.

Advertisement