Sign in to follow this  

Problem with IDirect3DTexture8

This topic is 3723 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 have a strange problem with my class and texture as a member of this class. Here is a code of my class (as you can see this class is simple):
class plansza
{
public:
	plansza(short nrPlanszy,LPDIRECT3DDEVICE8 d3dDev,RECT *nmeshRect);
	~plansza();
	bool isPointOnSurface(float x,float y);
private:
	RECT *meshRect;
	LPDIRECT3DTEXTURE8 planszaView;
};

plansza::plansza(short nrPlanszy, LPDIRECT3DDEVICE8 d3dDev,RECT *nmeshRect)
{
	meshRect=nmeshRect;
	char path[10];
	memset(path,0,10);
	if(nrPlanszy<9)sprintf(path,"levels\\0%d.bmp",nrPlanszy);
	else sprintf(path,"levels\\%d.bmp",nrPlanszy);
	D3DXCreateTextureFromFileEx(d3dDev,path,0,0,1,0,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,
		D3DX_DEFAULT ,D3DX_DEFAULT ,0,NULL,NULL,&planszaView);
	
}

plansza::~plansza()
{ 
	planszaView->Release();
}

bool plansza::isPointOnSurface(float x,float y)
{
	D3DSURFACE_DESC desc;
	planszaView->GetLevelDesc(0,&desc);
	
      //here I'll put some code that will make sth with texture
	return true;
}
(sorry for some polish identifiers but it's not important) I know that function from class' constructor creates texture correctly because when I copy planszaView->GetLevelDesc(..) to constructor it works fine. Destructor isn't called anywere in my code before using isPointOnSurface method but when I use this method - it turnes out that planszaView equales NULL . Could sth happen with IDirect3DTexture8 object without using Release method and outside this class ? Sorry for my mistakes because my english is still not perfect.

Share this post


Link to post
Share on other sites
Path isn't long enough.

"levels\nn.bmp" and a nul.
123456789ABCD + E

So your path variable has to be 14 at an absolute minimum.

You can also have the leading 0 added automatically via %02d.

It's possible the files aren't found or some other problem occured too. Use d3dx9d.lib (the d suffix means debug). Also enable the D3D debug runtime. You should now get details of why the texture load failed in your output window. Regardless of why it failed for you, your app should handle failure to load textures gracefully.

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
Path isn't long enough.


Ah, another victim of C-style strings! Don't use them. They are error-prone, as you found out the hard way. Spend some time learning how to use std::string and its associated streams:


std::basic_ostringstream<TCHAR> path;
path << "levels\\";
if (nrPlanszy < 9)
path << "0";
path << nrPlanszy << ".bmp" << std::ends;
D3DXCreateTextureFromFileEx(d3dDev, path.str().c_str(),
0,0,1,0,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,
D3DX_DEFAULT ,D3DX_DEFAULT ,0,NULL,NULL,&planszaView);

Share this post


Link to post
Share on other sites
Thank you! It's so simple error, I don't know why I didn't notice that. But as I said, when I placed GetLevelDesc right after D3DXCreateTextureFromFileEx, application worked fine. So I thought that texture is loaded correctly. Only when GetLevelDesc was called from another function my program interrupted his working.

Share this post


Link to post
Share on other sites

This topic is 3723 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.

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