# DXCreateTextureFromFile + Pointers

## Recommended Posts

/* cMesh.h */
class cMesh
{
// *snip*
LPDIRECT3DTEXTURE9* MeshTextures;
};

/* cMesh.cpp */
{
// *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 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 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 on other sites
Yeah that was snipped out, but it is in there.

##### Share on other sites
Oh wicked, it worked now =) thanks mate

Looks kinda weird... but I guess that's another problem hehe

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627646
• Total Posts
2978384

• 10
• 12
• 22
• 13
• 33