When I import a new mesh it would break in the draw function and tell me AccessVoilationException where it sets up the IndexBuffers to be drawn. My guess is that it's trying to access a region in memory that isn't there.
Each time in the Import Mesh it generates new totalVertices and totalIndexes for the model struct. Once it obtains the vertex count inside the mesh - it will createa a new size for the struct. I don't know if this could be it.
The Mesh class is outside of the managed area which is intialized with every new managed Model call.
Additionally notes, could it be because the draw function is inside the editor's timer1 form control?
C++ Managed Assembly - model struct.
struct MODEL {
ID3D11Buffer *pVBuffer; // the pointer to the vertex buffer
ID3D11Buffer *pIBuffer; // the pointer to the index buffer
ID3D11ShaderResourceView *pTexture; // the pointer to the texture
int totalVertices;
int totalIndices;
D3DXMATRIX rotation_Matrix;
D3DXMATRIX translation_Matrix;
D3DXMATRIX scale_Matrix;
D3DXMATRIX worldMatrix;
D3DXMATRIX modelMatrix;
};
MODEL *model;
If it's able to load one mesh - this should be the problem, right?
C++ Managed Code - Model Draw Function.
void Draw() {
// select which vertex buffer to display
UINT stride = sizeof(Mesh::VERTEX);
UINT offset = 0;
devcon->IASetVertexBuffers(0, 1, &MESH->model[idCount].pVBuffer, &stride, &offset);
devcon->IASetIndexBuffer(MESH->model[idCount].pIBuffer, DXGI_FORMAT_R32_UINT, 0);
// select which primtive type we are using
devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
devcon->UpdateSubresource(pCBuffer, 0, 0, &cBuffer, 0, 0);
devcon->PSSetShaderResources(0, 1, &MESH->model[idCount].pTexture);
devcon->DrawIndexed(MESH->model[idCount].totalVertices, 0, 0);
}
I thought because when I initialize the buffers after loading everything from file. It would understand:
MESH->model[idCount].pVBuffer
idCount is incremented every new mesh is imported.
Would it be better to have the DrawIndexed function where I have it present the scene or in the model's draw function? Would I have to bring the cBuffer into the struct as well?
Thanks everyone!