Sign in to follow this  
Jemburula

DXCreateTextureFromFile + Pointers

Recommended Posts

Hey, I need some help read the comments for more info
/* cMesh.h */
class cMesh
{
  // *snip*
  LPDIRECT3DTEXTURE9* MeshTextures;
};

/* cMesh.cpp */
bool cMesh::Load(string FileName)
{
  // *snip*
  string Path = "Data\\Tex\\Tiny_skin.dds";
  HR = D3DXCreateTextureFromFile(D3D->GetD3DDevice(), Path.c_str(), &MeshTextures[i]);
  // *snip*
};

The HR returns a D3DERR_INVALIDCALL - Invalid call so I think there is something wrong with the parameters I passed? Not really sure. But yeah I can't seem to quite figure what's up but I presume it's something to do with the pointer situation which is getting me really confused... I debugged and stepped through step by step and some interesting things occured: std::c_str returned 0x00c62f80 <Bad Ptr> const char * &MeshTextures[i] 0x00000000 IDirect3DTexture9 * * So my Path is possibly screwing it up? Which is leading the Mesh to still equal NULL. Hmm... I'm not quite sure [confused] so yeah any help would be very much appreciated [smile] -Jemburula

Share this post


Link to post
Share on other sites
For extra reference I thought I'd just post a chunk of the cMesh::Load just in case you needed extra info

// Copy the data from MaterialBuffer into MeshMaterials and MeshTextures
for(DWORD i = 0; i < this->NumMaterials; ++i)
{
this->MeshMaterials[i] = Materials[i].MatD3D;
this->MeshMaterials[i].Ambient = this->MeshMaterials[i].Diffuse;
// Create the texture if it exists
this->MeshTextures = NULL;
if(Materials[i].pTextureFilename)
{
Path = "Data\\Tex\\Tiny_skin.dds";// + Materials[i].pTextureFilename;
LPCSTR FinalPath = Path.c_str();
HR = D3DXCreateTextureFromFile(D3D->GetD3DDevice(), FinalPath, &MeshTextures[i]);
if(FAILED(HR))
{
D3D->WriteConsole("Failed: cMesh::Load texture with file " + Path);
Error("Failed: cMesh::Load->" + Path + ": " + (string)DXGetErrorString9(HR) + " - " + (string)DXGetErrorDescription9(HR));
PostQuitMessage(0);
return false;
};
};
};

Share this post


Link to post
Share on other sites
Your MeshTextures is a pointer to LPDIRECT3DTEXTURE9... so you need to initialise it with MeshTextures = new LPDIRECT3DTEXTURE9[numTextures];
Only then can you do &MeshTextures[i]. I don't know if you snipped this out or what, but if the array is not allocated, in debug mode you would pass a zero pointer to the D3DXCreateTextureFromFile, which would make it fail.

I don't think there's anything wrong with the string usage.

(edit)
Now that you posted your init, this is the fault: this->MeshTextures = NULL; You're indicing into a null pointer array.

Share this post


Link to post
Share on other sites

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