Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Lost Device

Started by Der Tim 5 replies 950+ views
Original Post
Der Tim
Der Tim
Hi guys, my name is Tim and I am a new user. Sorry that my English is not perfekt(I come from Germany ;-)). I started with programming Managed DirectX, not the 2.0.0 assambly, the other. If I start my application, change the window with TAB and the ALT and try to remove to my fullscreen mode I get a exception. A indexbuffer, vertexbuffer or an other think is not in use. I have programmed following source: public void OnDeviceReset(object sender, EventArgs e) { currentDevice.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)this.Width / this.Height, 1.0f, 1000.0f); currentDevice.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 9.5f, 17.0f), new Vector3(), new Vector3(0, 1, 0)); if ((currentDevice.DeviceCaps.VertexProcessingCaps.SupportsDirectionalLights) && (currentDevice.DeviceCaps.MaxActiveLights > 1)) { //First Light currentDevice.Lights[0].Type = LightType.Directional; currentDevice.Lights[0].Diffuse = Color.White; currentDevice.Lights[0].Direction = new Vector3(1, -1, -1); currentDevice.Lights[0].Enabled = true; //Second Light currentDevice.Lights[1].Type = LightType.Directional; currentDevice.Lights[1].Diffuse = Color.White; currentDevice.Lights[1].Direction = new Vector3(-1, 1, -1); currentDevice.Lights[1].Enabled = true; } else { currentDevice.RenderState.Ambient = Color.White; } } public void OnLostDevice(object sender, EventArgs e) { Console.Out.WriteLine("HH"); int result; int lostDeviceValue = (int)ResultCode.DeviceLost; currentDevice.CheckCooperativeLevel(out result); if (lostDeviceValue == (int)ResultCode.DeviceLost) { //Wait till the Device is ready to reset while (result == lostDeviceValue) { System.Threading.Thread.Sleep(100); currentDevice.CheckCooperativeLevel(out result); } //Okay, wie have an new State //If it is Device not Reset, we can reset it if (result == (int)ResultCode.DeviceNotReset) currentDevice.Reset(currentDeviceManager.PresentParameters); } } private void Game_Paint(object sender, PaintEventArgs e) { if (currentDevice.CheckCooperativeLevel()) { currentDevice.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0); currentDevice.BeginScene(); { ; } currentDevice.EndScene(); currentDevice.Present(); } } if (caps.DeviceType == DeviceType.Hardware) { foreach(Format potentialBackBuffer in backBufferTypes) { if(fullscreen) displayFormat = potentialBackBuffer; else displayFormat = Manager.Adapters.Default.CurrentDisplayMode.Format; if(Manager.CheckDeviceFormat(selectedAdapter,DeviceType.Hardware,displayFormat,Usage.RenderTarget,ResourceType.Surface,potentialBackBuffer)) { if(Manager.CheckDeviceType(selectedAdapter,DeviceType.Hardware,displayFormat,potentialBackBuffer,fullscreen)) { bool fullscreencheck = false; if (fullscreen) { fullscreencheck = true; } else { if(Manager.CheckDeviceFormatConversion(selectedAdapter,DeviceType.Hardware,potentialBackBuffer,displayFormat)) fullscreencheck = true; } if(fullscreencheck) { foreach (DepthFormat potentialZBuffer in zBufferTypes) { if(Manager.CheckDeviceFormat(selectedAdapter,DeviceType.Hardware,potentialBackBuffer,Usage.DepthStencil,ResourceType.Surface,potentialZBuffer)) { //if(Manager.CheckDepthStencilMatch(selectedAdapter,DeviceType.Hardware,displayFormat,potentialBackBuffer,potentialZBuffer) //{ if(presentParameters == null) { presentParameters = new PresentParameters(); presentParameters.SwapEffect = SwapEffect.Discard; presentParameters.AutoDepthStencilFormat = potentialZBuffer; presentParameters.Windowed = !fullscreen; presentParameters.BackBufferHeight = DisplayMode.Height; presentParameters.BackBufferWidth = DisplayMode.Width; presentParameters.BackBufferFormat = potentialBackBuffer; presentParameters.EnableAutoDepthStencil = true; presentParameters.PresentationInterval = PresentInterval.Immediate; } //} } } } } } } }
shiftybits
shiftybits
Hi,

When you reset your device, you must also reset your vertex and index buffers. I have not used managed DirectX, but in C++ this is done by calling OnLostDevice() and OnResetDevice() on such objects.

These can be called inside your own functions where you are reseting your projection matrix, lights, and render states already.

Hope that helps.
Der Tim
Der Tim
Hi shiftybits,

the problem is that I don´t have an index or vertex buffer.
Im my application are the lights the only restartable thing.

Have you an other idea?

TIM :)
shiftybits
shiftybits
Hey Tim,

Like I said, I'm not very familiar with managed DirectX. However, I have had similar problems before with C++ DirectX.

The problem is that the device cannot be reset unless all your other objects have been reset or released first. Is the exception you are getting called 'DeviceLostException'? If so, try to call Reset() or Release() on your lights, matrices, and any other objects you have during your OnLostDevice function, before you call currentDevice.Reset().

Again, I'm not sure if lights in mangaged DirectX have this functionality, but it's a good place to start looking. If not, the lost device page in the mangaged DirectX documentation might have some info that will help you out.
Der Tim
Der Tim
Hi guys,

I am not sure but I think first I get a lost device exception and this funktion will after reset starts a rest device.

I have upload this thinks for you.

http://rapidshare.de/files/31964103/Dodger.rar.html

It would be very nice if somebody look at this project.
I think the code is as i would explain it.


TIM :)
Evil Steve
Evil Steve
What exception do you get?

When your device is reset, you have to treat it like it's just been created, and reset all of your render states, stream sources, transforms, and all re-create all resources created in the default pool.
Der Tim
Der Tim
Hi EvilSteve,

I get a LostDeviceException.

TIM :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.