Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (3 posts)

How to avoid the "Non-zero reference count" warning

Last post 12/16/2007 3:11 PM by Johannes Scharl. 2 replies.
  • 12/15/2007 7:14 AM

    How to avoid the "Non-zero reference count" warning

    Hi everybody,

    I'm developing a DX 10 demo for one of my university projects that makes heavily use of render-to-texture, shadow maps, multiple post processing effects, etc.

    Until today, I have somehow managed to avoid the "The Direct3D device has a non-zero reference count, meaning some objects were not released." - warning after exiting the application. This was when compiling in debug mode, now I made my first release build and there I get the warning/error again.

    Now my question is: What do I exactly have to do to solve this problem. I always thought all I have to do is to do a SAFE_RELEASE() on resources like ID3D10Effect, ID3D10Texture2D, ID3D10ShaderResourceView, ID3D10RenderTargetView before exiting. This does not seem to be enough.

    - Which resources do I have to release?
    - What if a pointer to a resource was passed to another object and stored there again as a pointer? Do I have to release both pointers?
    - Is there any way to see which resources have not been released at a certain point in the program?

  • 12/16/2007 11:31 AM In reply to

    Re: How to avoid the "Non-zero reference count" warning

    Reply Quote

    You need to release anything that a Direct3D 10 call returns as out parameter.  Using Smartpointers can be very helpful for this job.

    If you pass a pointer to another resource you are only responsible for the references you hold not for the references that are hold by other resources.

    Pix can help you to know the life state of any Direct3D object at any time.

  • 12/16/2007 3:11 PM In reply to

    Re: How to avoid the "Non-zero reference count" warning

    Thank you!
    I have to dig into this Pix thing a little more. Until now, I tried to avoid it since I find it a quite hard to use compared to classic debugging.

    I have experienced another problem: I use DXUT, and sometimes (when I toggle VSync in the settings dialog for instance), the OnD3D10ReleasingSwapChain callback is not fired when exiting the application. I have solved this by setting a flag in OnD3D10ResizedSwapChain to true and to false in OnD3D10ReleasingSwapChain. If it is still true when OnD3D10DestroyDevice is called, I manually call OnD3D10ReleasingSwapChain from there.

    Can anybody confirm this behaviour? This seems like a bug to me, since DXUT should call OnD3D10ReleasingSwapChain automatically when it is necessary (i.e. when OnD3D10ResizedSwapChain has been called before and the application is about to close).
Page 1 of 1 (3 posts) Previous Discussion Next Discussion