Jump to content
  • Advertisement
Sign in to follow this  
Game_XinBing

Why occur "The D3D device has a non-zero reference count"?

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

Error Message is this : The D3D device has a non-zero reference count, meaning some objects were not released. I write a simple code using DX9's DXUT framework. I define a new class: .h file: ====================================================================== class CMyMesh01_One { public: CMyMesh01_One(void); ~CMyMesh01_One(void); public: bool LoadMeshFromFile(char filename[], LPDIRECT3DDEVICE9 & pD3DDevice); public: LPDIRECT3DVERTEXDECLARATION9 m_pVD; struct stctVertex { float x, y, z; DWORD color; }; }; ======================================================================= .cpp file: ======================================================================= #include "dxstdafx.h" #include "MyMesh01_One.h" CMyMesh01_One::CMyMesh01_One(void) {m_pVD = NULL;} CMyMesh01_One::~CMyMesh01_One(void) { if (m_pVD) { m_pVD->Release(); m_pVD = NULL; } } bool CMyMesh01_One::LoadMeshFromFile(char filename[], LPDIRECT3DDEVICE9 & pD3DDevice) { //Vd D3DVERTEXELEMENT9 decl[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, D3DDECL_END() }; HRESULT hr; V(hr = pD3DDevice->CreateVertexDeclaration(decl, &m_pVD)); return true; } ========================================================================== then, i declare a CMyMesh01_One g_clsMyMesh01_One; in main program(EmptyProject.cpp) call in DXUT framework's function HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { g_clsMyMesh01_One.LoadMeshFromFile("C:\\test.txt", pd3dDevice); return S_OK; } but Error occur: Error Message is this : The D3D device has a non-zero reference count, meaning some objects were not released. Why it is occur? Thank you!

Share this post


Link to post
Share on other sites
Advertisement
While you Release your vertex declaration in CMyMesh01_One's destructor, for g_clsMyMesh01_One this gets called after you attempt to Release your D3D device, not before. This is because g_clsMyMesh01_One has global scope.

You will need to restructure your code so that the destructor gets called before attempting to release the D3D device.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!