D3DXCreateTextureFromFile always fails.

Started by
2 comments, last by darkelf2k5 17 years, 7 months ago
I am trying to load a texture from a file that is in the right directory and I have tried different file types but my function is still returning an error of D3DERR_INVALIDDATA when I am debugging. When I tried to load the .exe without debugging it closes immediately, showing that mSprite->End( ) function failed. Here is the function... bool cSprite::load( char *Filename ) { HRESULT hResult; if( mAbyss == NULL ) return false; if( Filename == NULL ) return false; if( hResult = D3DXCreateTextureFromFile( mAbyss->getDevice( ), Filename, &mTexture ) ) { if( hResult == D3DERR_NOTAVAILABLE ) { MessageBox(NULL, "Function: cSprite.load( ), Error: D3DERR_NOTAVAILABLE.", "Error", MB_OK); } else if( hResult == D3DERR_OUTOFVIDEOMEMORY ) { MessageBox(NULL, "Function: cSprite.load( ), Error: D3DERR_OUTOFVIDEOMEMORY.", "Error", MB_OK); } else if ( hResult == D3DERR_INVALIDCALL ) { MessageBox(NULL, "Function: cSprite.load( ), Error: D3DERR_INVALIDCALL.", "Error", MB_OK); } else if ( hResult == D3DXERR_INVALIDDATA ) { MessageBox(NULL, "Function: cSprite.load( ), Error: D3DERR_INVALIDDATA.", "Error", MB_OK); } else if ( hResult == E_OUTOFMEMORY ) { MessageBox(NULL, "Function: cSprite.load( ), Error: E_OUTOFMEMORY.", "Error", MB_OK); } else { MessageBox(NULL, "Function: cSprite.load( ), Error: UNKNOWN_ERROR.", "Error", MB_OK); } } return true; } bool cSprite::end( ) { if( mSprite == NULL ) return false; if( FAILED( mSprite->End( ) ) ) return false; return true; } I'd appreciate any suggestions as to why it is erroring out.
Advertisement
Are u sure the getDevice() gives you a valid device ?
What is the type of mTexture ?
There is nothing that can't be solved. Just people that can't solve it. :)
Test to try with D3DXCreateTextureFromFileEx
D3DERR_INVALIDDATA is usually caused by wrong pathname for the texture.

There is an easier way to get HRESULT error feedback. Check out this header.

#include <dxerr9.h>
#pragma comment ( lib, "dxerr.lib" )
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!

This topic is closed to new replies.

Advertisement