Proper Resource Disposal :: Managed DirectX

Started by
3 comments, last by Zipster 19 years, 10 months ago
Sometimes when I exit my managed DirectX application, it will hang inside the main form''s Dispose function (when I break the application, it references the closing bracket). I can only assume that this means it''s having trouble disposing of my DirectX resources. Right now, I have a Direct3D device, a single vertex buffer, and a collection of objects that manage their own index buffer. Each object has a reference to the Direct3D device so it can call DrawIndexedPrimitives. When I add call to Device.Dispose() to the form''s dispose function, when I break the application after it hangs, the breakpoint is on the statement immediately following the Dispose call. This is why I assume there is a problem disposing of the graphics device. I''ve verified that it only hangs when the vertex buffer is created and each object holds a reference to the device. I''m just looking for some suggestions on how to safely dispose of all my resources, and make sure my application doesn''t try to access them after they''ve been disposed of. Also, any ideas as to why it would hang on disposal would be greatly appreciated
Advertisement
release the objects in reverse order for their creation.the last created object should be released first.
I had the exact same problem and it was because my device dispose was out of order as mohamed suggested to you to look at. In my case it didn''t happen alot maybe 1 out of 20 times but was enough to look into :-)
I don''t really have that many resources, and even when I add a call to Device.Dispose it hangs, on that very call. Sometimes not for very long, but sometimes for so long that I have to end the process before it''s complete.

Disposing of the vertex buffers and index buffers is no problem, but it really doesn''t like disposing the graphics device. Could it have to do with the device trying to dispose of the vertex/index buffers itself?
have you tried disposing the vertex and index buffers before disposing the device?

This topic is closed to new replies.

Advertisement