• Advertisement
Sign in to follow this  

Leak problem C++ and DirectX (SOLVED)

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

HI i'v got a leak problem i cannot solve. i created a staticsprite class with render func.Here is the problem. I detected the leak , it is my StaticSprite * back; //defined in globals.h and when i comment it everywhere there are no leaks. To easy things for me i put in my main.cpp file code like this while( mMsg.message!=WM_QUIT ) if( PeekMessage.... .... else { back = new StaticSprite(&gfx->D3DDevice,"MainMenu.bmp"); PostQuitMessage(3); SafeDelete(back); } ... And it reports 2 leaks not so big (442 bytes) as irittating. To be funnier when i call back->render (in a loop to display a background) it reports 6 leaks. If i comment back there are no leaks. Here are my StaticSprite.h //i am not using .cpp If anyone has some idea it will help me a lot Thanks.
#ifndef StaticSprite_h
#define StaticSprite_h

#include <d3dx9.h>
#include <windows.h>

class StaticSprite
	StaticSprite(LPDIRECT3DDEVICE9* g_pD3DDevice,LPCSTR TextureName);
	virtual void Render();
	void SetPosition(float x,float y,float z);
	void SetCenter(float x,float y,float z);
	D3DXVECTOR3 GetPosition(){return m_position;};
	D3DXVECTOR3 GetCenter(){return m_center;};

	D3DXVECTOR3				m_position;
	D3DXVECTOR3				m_center;
	bool					visible;
	D3DXIMAGE_INFO			m_ImageInfo;
	LPDIRECT3DTEXTURE9      m_SpriteTexture;
	LPD3DXSPRITE            m_Sprite;
StaticSprite::StaticSprite(LPDIRECT3DDEVICE9* g_pD3DDevice,LPCSTR TextureName)
	m_SpriteTexture = NULL;
	m_Sprite  = NULL;
	m_position.x = 0.0f;
	m_position.y = 0.0f;
	m_position.z = 0.0f;
	m_center.x = 0.0f;
	m_center.y = 0.0f;
	m_center.z = 0.0f;
	visible = true;
	D3DXCreateTextureFromFileEx( *g_pD3DDevice,
                                 D3DX_DEFAULT_NONPOW2  , // I had to set width manually. D3DPOOL_DEFAULT works for textures but causes problems for D3DXSPRITE.
                                 D3DX_DEFAULT_NONPOW2  , // I had to set height manually. D3DPOOL_DEFAULT works for textures but causes problems for D3DXSPRITE.
                                 1,   // Don't create mip-maps when you plan on using D3DXSPRITE. It throws off the pixel math for sprite animation.
                                 &m_SpriteTexture );
	D3DXCreateSprite( *g_pD3DDevice, &m_Sprite );

void StaticSprite::Render()
	if (visible == true)
	m_Sprite->Begin( D3DXSPRITE_ALPHABLEND );

    m_Sprite->Draw( m_SpriteTexture,
                          NULL,  // use entire image 
                          D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );
void StaticSprite::SetPosition(float x,float y,float z)
	m_position.x = x;
	m_position.y = y;
	m_position.z = z;

void StaticSprite::SetCenter(float x,float y,float z)
	m_center.x = x;
	m_center.y = y;
	m_center.z = z;


[Edited by - zlatko_bre_1985 on July 8, 2005 11:44:19 AM]

Share this post

Link to post
Share on other sites
I isolated code that is making leaks but rgiht now i'm TOTALY confused:
it is belive me or not dx createsprite()
""D3DXCreateSprite( *g_pD3DDevice, &m_Sprite );""
iv come to that by commenting whole inside of StaticSprite::StaticSprite()
and uncommenting line by line.HOW IS THIS POSSIBLE???

Share this post

Link to post
Share on other sites
I don't see where you define your destructor. That's probably what it is, you aren't remembering to release everything when your done with it. Make sure you have a destructor and a delete call somewhere.

Share this post

Link to post
Share on other sites
Yes yes, thank you Oberon_Command so much i forgot to release the texure and the sprite.Many many thanks!
And by the way can i change somehow add "solved" to the title of the tread?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement