DXCreateTextureFromFile + Pointers

Started by
3 comments, last by Jemburula 17 years, 11 months ago
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);
  // *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 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
What we do in life... Echoes in eternity
Advertisement
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 = Materials.MatD3D;    this->MeshMaterials.Ambient = this->MeshMaterials.Diffuse;    // Create the texture if it exists    this->MeshTextures = NULL;    if(Materials.pTextureFilename)    {      Path = "Data\\Tex\\Tiny_skin.dds";// + Materials.pTextureFilename;      LPCSTR FinalPath = Path.c_str();      HR = D3DXCreateTextureFromFile(D3D->GetD3DDevice(), FinalPath, &MeshTextures);      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;      };    };  };
What we do in life... Echoes in eternity
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 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.
Yeah that was snipped out, but it is in there.
What we do in life... Echoes in eternity
Oh wicked, it worked now =) thanks mate

Looks kinda weird... but I guess that's another problem hehe
What we do in life... Echoes in eternity

This topic is closed to new replies.

Advertisement