Sign in to follow this  
MTclip

Need to release ???

Recommended Posts

question... I creating a wrapper class for D3dxsprite.. example::
#pragma once

class CSprite
{
public:
	LPD3DXSPRITE		m_sprite;
	LPDIRECT3DDEVICE9        m_pDevice;
	BOOL			isCreated;
      //////////////////////////////////////////
	CSprite(LPDIRECT3DDEVICE9 device);
	~CSprite(void);
	HRESULT create()
	HRESULT setDevice(LPDIRECT3DDEVICE9 device)
	HRESULT setTexture(CTexture *texture)
};

my question has to do with the "m_pDevice" upon instantiation of the "sprite" I set the m_pDevice equal to the device sent in the constructor... So do i need to call the LPDIRECT3DDEVICE9->Release() for "m_pDevice" when i am done with the sprite???? .. .. what i really wanted to do was make "m_pDevice" a "LPDIRECT3DDEVICE9 * " but i had problems getting this to work... ;P

Share this post


Link to post
Share on other sites
Unless you are doing m_pDevice->AddRef() in the constructor, no. Simply making a copy of a pointer will not increase an interface's reference counter. The only time that will happen is when D3D code explicitly increases it, which you have to watch out for. For example, if you call IDirect3DDevice9::GetSurfaceLevel() you must eventually release the returned surface, because it increases that surface's reference count.

Remember, a resource is only actually ever deleted when it's reference count reaches 0. So you could call Release() on a D3DDevice 5 times, without it being deleted (just make sure it has 5 ref counts first [smile]).

Share this post


Link to post
Share on other sites

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