I will post it in the C++ specific board tomorrow, originally I planned to ask something more game specific but I changed it and never changed boards.
I know using vectors should be simple and yet it is giving me a ton of trouble. I'm not quite sure what other code could possibly be helpful but I'll try anyway.
Here is the code for the entire function where I fill out TempMesh and add it to the vector (MESH_TEAPOT is predefined elsewhere).
Code:
int MeshContainer::LoadMesh(IDirect3DDevice9* &g_pd3dDevice, int iMeshNum) {
Mesh *TempMesh = new Mesh();
switch(iMeshNum) {
case MESH_TEAPOT: // Create a Teapot
if(FAILED(D3DXCreateTeapot(g_pd3dDevice, &TempMesh->MeshData, 0)))
return false;
TempMesh->dwNumSubsets = 0;
TempMesh->dwID = 0;
break;
default:
return false;
break;
}
vector<Mesh *> * memAddress = &MeshList;
if(memAddress == NULL)
MessageBox(NULL, "memAddress == NULL", "Error!", MB_ICONSTOP | MB_OK);
MeshList.push_back(TempMesh);
if(TempMesh->MeshData != NULL) {
TempMesh->MeshData->Release();
TempMesh->MeshData = NULL;
}
delete TempMesh;
return true;
}
Here is the Mesh structure (I haven't finished it becuause I haven't been able to get the vector thing to work):
Code:
struct Mesh {
DWORD dwID;
DWORD dwNumSubsets;
LPD3DXMESH MeshData;
Mesh() {
dwID = 0;
dwNumSubsets = 0;
MeshData = NULL;
}
};
And here is the MeshContainer class (it is partially inspired from some of your ideas on research management Bubba and I haven't added much to it at all):
Code:
class MeshContainer {
private:
vector<Mesh *> MeshList;
public:
MeshContainer() {}
~MeshContainer() {
if(MeshList.size() > 0) {
for(DWORD i=0; i<MeshList.size(); i++) {
if(MeshList[i] != NULL) {
MeshList[i]->MeshData->Release();
MeshList[i] = NULL;
}
}
MeshList.clear();
}
}
void DrawMesh(DWORD dwMeshID);
int LoadMesh(IDirect3DDevice9* &g_pd3dDevice, int iMeshNum);
};