Sign in to follow this  

[Managed D3D] Weird bug in resizing

This topic is 4661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've encountered a weird bug when trying to resize an application using Managed DirectX. The problem is that after handling a lost device due to control-alt-delete, subsequent losses of the device will generate a D3DERR_INVALIDCALL exception. Here's how to reproduce the bug: * I took the sample code from the 'Device Recovery Tutorial' located at http://pluralsight.com/wiki/default.aspx/Craig.DirectX/DeviceRecoveryTutorial.html (see the full source at the bottom of the article) and compiled it in a new project. * Run the application, the triangle will start spinning * Press control-alt-delete, press escape to go back to the application. Wait until it has reset itself and you see the triangle spin again. * Then either resize the form or press control-alt-delete again to trigger another loss of the device. The application crashes with the following stacktrace:
(.. lots of symbols being loaded..)
Device was lost
Device successfully reset
Device was lost
An unhandled exception of type 'Microsoft.DirectX.Direct3D.InvalidCallException' occurred in microsoft.directx.direct3d.dll

Additional information: Error in the application.


Unhandled Exception: Error in the application.
-2005530516 (D3DERR_INVALIDCALL)
   at Microsoft.DirectX.Direct3D.Device.Reset(PresentParameters[] presentationParameters)
   at Craig.Direct3D.Game.AttemptRecovery() in c:\bla\bla\game.cs:line 209
   at Craig.Direct3D.Game.Render() in c:\bla\bla\game.cs:line 142
   at Craig.Direct3D.Game.Main() in c:\bla\bla\game.cs:line 22
The program '[5520] bla.exe' has exited with code 0 (0x0).
I am using Win XP SP2 with the February 2005 SDK, testing on a Radeon 9800 Pro. 1) Can anyone reproduce the exception? 2) What would be the cause, and what would be the solution? Thanks in advance!

Share this post


Link to post
Share on other sites
Well, I managed to enable DirectX Debugging, which is giving me some additional information. It seems that somehow the vertexbuffer that I am using is not being released properly, thus resulting in an invalid call upon trying to reset the device. The buffer is made in the DEFAULT pool and like the code in the example from the previous post, I use VertexBuffer.Dispose() to dispose my buffer whenever the device is lost.

What else do I need to do to release that Vertexbuffer?

Here's a trace:

Device was lost
(..I pressed contrl-alt-delete here, followed by escape to go back to the app..)
Direct3D9: :DoneExclusiveMode
Handling DeviceNotResetException
OnDeviceLost
Direct3D9: (INFO) :Failed to create driver indexbuffer
Device successfully reset
OnDeviceReset
SetupDevice

(..Application is running again..)
(..I pressed contrl-alt-delete here, followed by escape to go back to the app..)
OnDeviceLost
Device was lost
Handling DeviceNotResetException
OnDeviceLost
Direct3D9: (ERROR) :The following D3DPOOL_DEFAULT surfaces/buffers/textures still exist
Direct3D9: (ERROR) : D3DRTYPE_VERTEXBUFFER
Direct3D9: (ERROR) :All user created D3DPOOL_DEFAULT surfaces must be freed before Reset can succeed. Reset Fails.
Direct3D9: (ERROR) :Reset failed and Reset/TestCooperativeLevel/Release are the only legal APIs to be called subsequently
An unhandled exception of type 'Microsoft.DirectX.Direct3D.InvalidCallException' occurred in microsoft.directx.direct3d.dll


'OnDeviceLost' = event handler for lost device
'OnDeviceReset' = event handler for device reset
'SetupDevice' = setup of render states, called by 'OnDeviceReset'
'Device was lost' = Device.Present() gives a DeviceLost exception
'Handling DeviceNotResetException' = The NotReset exception is handled, which calls for Device.Reset();

Share this post


Link to post
Share on other sites

This topic is 4661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this