Sign in to follow this  

Tracking down Dispose() bugs

This topic is 4672 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
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
when are you calling dispose() and why? are you sure that your vertex buffer object is not already Disposed?

Share this post


Link to post
Share on other sites

This topic is 4672 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