Tracking down Dispose() bugs

Started by
2 comments, last by mohamed adel 19 years, 1 month ago
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
--------------Trans2D - 2D library for C# / Managed DirectX
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.
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]
--------------Trans2D - 2D library for C# / Managed DirectX
when are you calling dispose() and why? are you sure that your vertex buffer object is not already Disposed?

This topic is closed to new replies.

Advertisement