Jump to content
  • Advertisement
Sign in to follow this  
_Flecko

Tracking down Dispose() bugs

This topic is 4921 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'm getting AccessViolationExceptions from calls to Dispose() (on vertex buffers, mostly), which evidently means some method I passed the resource to is still using it when I want to dispose of it. I can't figure out what, though. Can anyone think of good ways to track what objects are using a given resource, or otherwise figure out what's causing the problems? Thanks, Max

Share this post


Link to post
Share on other sites
Advertisement
Yes. And assuming you are using DirectX, it is already there. All resource objects in DirectX implement the IUnknown interface, which gives you reference-counted-objects. So, per object it is stored how many other objects refer to it. If the last reference is released the object can be disposed of.

So the solution you might want to try is the following:

1) Each new object that uses the vertex buffer should call pVB->AddRef() to increase the reference count.
2) On destruction each of those objects should call pVB->Release(), which decreases the reference count and, for the last last one, destructs the object.
3) You might use QueryInteface() to retrieve the number of referencing objects and do a dispose call if it is one and the next line says Release().

Greetz,

Illco.

Share this post


Link to post
Share on other sites
I'm using Managed DirectX, and it seems that the VertexBuffer class has no exposed AddRef or Release methods. There is an IUnknown interface defined in Microsoft.DirectX.Diagnostics - its documentation says it gives access to unmanaged portions of the API, and that it's not meant to be used by client code. Nnot that that's ever stopped me before, but I can't seem to actually get access to IUnknown.

Is there an equivalent way of checking references to an resource with Managed DX? Also, even if I figured out that the device (or some other object) is storing a reference to my vb, how would I get it to let go of it?

[Edited by - _Flecko on April 1, 2005 7:45:17 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!