#ifndef StaticSprite_h
#define StaticSprite_h
#include <d3dx9.h>
#include <windows.h>
class StaticSprite
{
public:
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;
protected:
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,
TextureName,
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.
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
&m_ImageInfo,
NULL,
&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
&m_center,
&m_position,
D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );
m_Sprite->End();
}
};
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;
};
#endif
Leak problem C++ and DirectX (SOLVED)
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.
[Edited by - zlatko_bre_1985 on July 8, 2005 11:44:19 AM]
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???
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???
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement