• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Joakim1234

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

13 posts in this topic

I'm using a little helper function to create vertex buffers:
[CODE]void AssetManager::CreateVertexBuffer(ID3D11Buffer** buffer, unsigned int bufferSize, void* vertices, D3D11_USAGE bufferUsage, D3D11_CPU_ACCESS_FLAG processorAccess)
{
D3D11_BUFFER_DESC bufferDesc;
D3D11_SUBRESOURCE_DATA subResData;

bufferDesc.Usage = bufferUsage;
bufferDesc.ByteWidth = bufferSize;
bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = processorAccess;
bufferDesc.MiscFlags = 0;
bufferDesc.StructureByteStride = 0;

subResData.pSysMem = vertices;
subResData.SysMemPitch = 0;
subResData.SysMemSlicePitch = 0;
HR(gD3DDevice->CreateBuffer(&bufferDesc, &subResData, buffer));
}

[/CODE]And it causes a [b]E_INVALIDARG [/b]error,but doesn't give a clue about which argument is the invalid one.Here is how the function is called in the program:
[CODE]
vertexBuffer = 0;

VertexType* vertices = new VertexType[vertexCount];;

vertices[0].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); //just random values to see if it debugs at all
vertices[0].texture = XMFLOAT2(0.0f, 1.0f);
vertices[1].position = XMFLOAT3(0.0f, 1.0f, 0.0f);
vertices[1].texture = XMFLOAT2(0.5f, 0.0f);

vertices[2].position = XMFLOAT3(1.0f, -1.0f, 0.0f);
vertices[2].texture = XMFLOAT2(1.0f, 1.0f);


AssetManager->CreateVertexBuffer(&vertexBuffer,sizeof(VertexType)*vertexCount, &vertices);
[/CODE]

Could the problem be in "[i]bufferDesc.StructureByteStride = 0;[/i]"?Am I supposed to leave it at 0?Cause all the tutorial project files leave it at 0 and they compile just fine.But the problem can't be in the project itself,I linked all the needed libraries and the paths to the SDK.
0

Share this post


Link to post
Share on other sites
What are the default values for the bufferUsage and processorAccess parameters, since you dont specify them? D3D11_USAGE_DEFAULT and 0? Edited by SamiHuutoniemi
0

Share this post


Link to post
Share on other sites
[quote name='SamiHuutoniemi' timestamp='1343435910' post='4963813']
What are the default values for the bufferUsage and processorAccess parameters, since you dont specify them? 0 and 0?
[/quote][quote name='SamiHuutoniemi' timestamp='1343435910' post='4963813']
What are the default values for the bufferUsage and processorAccess parameters, since you dont specify them? 0 and 0?
[/quote]

They are
[CODE]void CreateVertexBuffer(ID3D11Buffer** buffer, unsigned int bufferSize, void * vertices, D3D11_USAGE bufferUsage = D3D11_USAGE_DEFAULT, D3D11_CPU_ACCESS_FLAG processorAccess = D3D11_CPU_ACCESS_READ);[/CODE]

It should result in the same buffer creation that I saw in a tutorial which used to work with no problems.
0

Share this post


Link to post
Share on other sites
I always set it to 0 if I go with D3D11_USAGE_DEFAULT. I dont think you can use D3D11_CPU_ACCESS_READ for this. Edited by SamiHuutoniemi
2

Share this post


Link to post
Share on other sites
[quote name='SamiHuutoniemi' timestamp='1343436192' post='4963816']
I always set it to 0 if I go with D3D11_USAGE_DEFAULT. I dont think you can use D3D11_CPU_ACCESS_READ for this.
[/quote][quote name='SamiHuutoniemi' timestamp='1343436192' post='4963816']
I always set it to 0 if I go with D3D11_USAGE_DEFAULT. I dont think you can use D3D11_CPU_ACCESS_READ for this.
[/quote]

lol it actually worked,but what kind of access does 0 mean?READWRITE?
1

Share this post


Link to post
Share on other sites
No. Default usage means that only the GPU can read and write. That other parameter has something to do with staging. Can't say I've never used it.
2

Share this post


Link to post
Share on other sites
Is vertexCount == 3?

[i]Your call:[/i]
AssetManager->CreateVertexBuffer(&vertexBuffer,sizeof(VertexType)*vertexCount, &vertices);

[i]Your definition:[/i]
void AssetManager::CreateVertexBuffer(ID3D11Buffer** buffer, unsigned int bufferSize, void* vertices, [b]D3D11_USAGE bufferUsage[/b], [b]D3D11_CPU_ACCESS_FLAG processorAccess[/b])

What are the default values?


ID3D11Buffer** buffer means pointer to pointer.
In the creation you have buffer pointer instead of *buffer pointer
HR(gD3DDevice->CreateBuffer(&bufferDesc, &subResData, *buffer));
0

Share this post


Link to post
Share on other sites
[quote name='Neometron' timestamp='1343436894' post='4963820']
Is vertexCount == 3?

[i]Your call:[/i]
AssetManager->CreateVertexBuffer(&vertexBuffer,sizeof(VertexType)*vertexCount, &vertices);

[i]Your definition:[/i]
void AssetManager::CreateVertexBuffer(ID3D11Buffer** buffer, unsigned int bufferSize, void* vertices, [b]D3D11_USAGE bufferUsage[/b], [b]D3D11_CPU_ACCESS_FLAG processorAccess[/b])

What are the default values?


ID3D11Buffer** buffer means pointer to pointer.
In the creation you have buffer pointer instead of *buffer pointer
HR(gD3DDevice->CreateBuffer(&bufferDesc, &subResData, *buffer));
[/quote]Firstly, it has already been solved. But to answer your questions. About the parameters: Default values. He specified them a bit up when I asked. About the pointer. If you look closely, buffer IS ID3D11Buffer**. It wouldn't have compiled otherwise.
2

Share this post


Link to post
Share on other sites
[quote name='SamiHuutoniemi' timestamp='1343436715' post='4963818']
No. Default usage means that only the GPU can read and write. That other parameter has something to do with staging. Can't say I've never used it.
[/quote]

This is the correct answer. The DX SDK clearly explains what combinations of parameters are valid, and CPU access read (the fact that you even want to do this sends more alarm bells, by the way) is not valid for default usage. MSDN page for D3D11_USAGE: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476259%28v=vs.85%29.aspx
2

Share this post


Link to post
Share on other sites
Thanks for showing me this,I guess it's not such a good idea to have a buffer creator function anyway [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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]
0

Share this post


Link to post
Share on other sites
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.
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0