• Advertisement
Sign in to follow this  

D3DXCreateTextureFromFileEx problem

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

EDIT: Using D3DXCreateTextureFromFile isntead of D3DXCreateTextureFromFileEx works fine, the texture is a 64x64 rbga png

EDIT: It appears the cause of the problem is if I pass a PALETTEENTRY to be filled. If I leave that field NULL I get no memory problems... Also whether I leave that field null or not the texture always loads and is visible when drawn.

EDIT: SOLVED - Didn't realise... my PALETTEENTRY m_oTexturePalette needed to be m_oTexturePalette[256]. Misinterpreted the description.

Having problems where calling D3DXCreateTextureFromFileEx is causing memory problems.

.h

class Texture
{
public:
Texture();
~Texture();

bool Initialize(IDirect3DDevice9* a_poIDirect3DDevice9, const char* a_pcFileName);

protected:
char* m_pcFileName;

IDirect3DTexture9* m_poTexture;

D3DXIMAGE_INFO m_oImageInfo;
PALETTEENTRY m_oTexturePalette;
};


.cpp

Texture::Texture()
{
m_pcFileName = 0;

m_poTexture = 0;

ZeroMemory(&m_oImageInfo, sizeof(m_oImageInfo));
ZeroMemory(&m_oTexturePalette, sizeof(m_oTexturePalette));
}

Texture::~Texture()
{
if (m_pcFileName)
{
delete [] m_pcFileName;
m_pcFileName = 0;
}

if (m_poTexture)
{
m_poTexture->Release();

m_poTexture = 0;
}
}

bool Texture::Initialize(IDirect3DDevice9* a_poIDirect3DDevice9, const char* a_pcFileName)
{
if (!m_poTexture)
{
m_pcFileName = new char[strlen(a_pcFileName) + 1];

strcpy(m_pcFileName, a_pcFileName);

HRESULT HResult = D3DXCreateTextureFromFileEx( a_poIDirect3DDevice9, m_pcFileName, D3DX_DEFAULT, D3DX_DEFAULT,
D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
D3DX_DEFAULT, D3DX_DEFAULT, 0,
&m_oImageInfo, &m_oTexturePalette, &m_poTexture);

if (FAILED(HResult))
{
return 0;
}

return 1;
}
else
{
return 0;
}
}


After calling "D3DXCreateTextureFromFileEx" (which returns a hresult of S_OK), m_pcFileName immediately turns to gibberish (as if the memory has been released).

Coming up too "if (m_pcFileName)" in the deconstructor, it returns true as the pointer is not set to null (should still point to a valid block of memory ><. So calling a delete again breaks my program.

Secondly, if I replace the current deconstructor with:

Texture::~Texture()
{
//if (m_pcFileName)
//{
//delete [] m_pcFileName;
// m_pcFileName = 0;
//}

if (m_poTexture)
{
m_poTexture->Release();

m_poTexture = 0;
}
}

I get a corruption of the heap error as the program exists the deconstructor.
m_poTexture->Release(); is called fine.

Share this post


Link to post
Share on other sites
Advertisement
Why are you messing around with raw character array strings instead of using a string class? Why are you even storing the texture file name in that class to begin with?

Share this post


Link to post
Share on other sites
No real reason why I'm using a character array over a string other than I'm not familiar with using the string yet (though I'm sure it's not difficulty..).
The texture is stored in a texture manager so when something requests a texture to be loaded it first checks to see if the texture is already loaded by strcmp'n the target filename/stored filenames.

Either using char arrays or storing the filename likely to cause this problem I'm having? :/

Share this post


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

  • Advertisement