ID3D11Device::CreateBuffer returning E_INVALIDARG for no apparent reason.[RESOLVED]

Started by
12 comments, last by _the_phantom_ 11 years, 8 months ago
Thanks for showing me this,I guess it's not such a good idea to have a buffer creator function anyway smile.png
Advertisement
There's nothing wrong with having a buffer creation routine so long as it works correctly. There are interesting and useful things you can do with one, including calling SetPrivateData to give your buffer a name (really helps tracking resource leaks), add your buffer to a resources list which is then used for Releasing them (you don't need to worry about adding each individual buffer to your shutdown routine anymore), consolidate your error checking for buffers in one place, etc.

But the buffer creation routine does have to work correctly first.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

What mhagain said!

If you'd like another sample of a create vertex buffer routine, this is one that I have in my framework:

[source lang="cpp"]void RenderableObject::CreateVertexBuffer(const Vertex* vertices, bool dynamic) {
HRESULT hr;

if (pVertexBuffer) {
pVertexBuffer->Release();
}

D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));

if (dynamic) {
vertexBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
vertexBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
}
else {
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.CPUAccessFlags = 0;
}
vertexBufferDesc.ByteWidth = textured ? sizeof(TextureVertex) * numVertices : sizeof(ColorVertex) * numVertices;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.MiscFlags = 0;

D3D11_SUBRESOURCE_DATA vertexBufferData;

ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
vertexBufferData.pSysMem = vertices;

hr = pD3DEngine->GetDevice()->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &pVertexBuffer);
if (hr != S_OK) {
MessageBox(0, L"RenderableObject::CreateVertexBuffer(): Could not create Vertex buffer!", L"Error!", 0);
}
pVertexBuffer->SetPrivateData(WKPDID_D3DDebugObjectName, sizeof(name) - 1, name.c_str());
}[/source]
Off the top of my head I don't know if it would have helped in this situation but in general when you hit a problem make sure you have the D3D debug runtime active - it will print out pretty detailed information about the problems which are happening to the Visual Studio output window.

This topic is closed to new replies.

Advertisement