Jump to content
  • Advertisement
Sign in to follow this  
Papadopol

Dx11 simple buffer

This topic is 2359 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. A simple question. I'm trying to create a function that creates a simple Dx11 buffer and it seems I got a lot of crashes and I dont know why. It seems that I dont know how to pass variables corectly thro a function.

original code:


struct SimpleVertex
{
FLOAT Pos[3]; // (X, Y, Z) coordinates of each vertex
float color[4];
float tex[2];
};

SimpleVertex vertices[6];
ID3D11Buffer* g_pVertexBuffer2;

// code..
//vertices are filled corectly
//code..

D3D11_BUFFER_DESC bd;
bd.Usage = D3D11_USAGE_IMMUTABLE;
bd.ByteWidth = sizeof( SimpleVertex )*6;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
bd.StructureByteStride = 0;

D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = vertices;
hr = g_pDevice->CreateBuffer( &bd, &initData, &g_pVertexBuffer2 );

//Everything works fine
}



My atetmpt of a function




int D3Device11::CreateBuffer(ID3D11Buffer* dx11_buffer, SimpleVertex *data, int ByteWidth) {

HRESULT error;

D3D11_BUFFER_DESC bd;
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = ByteWidth;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
bd.StructureByteStride = 0;

D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = data;


error = g_pDevice->CreateBuffer( &bd, &initData, &dx11_buffer );


if(FAILED(error)) {
MessageBox(NULL,L"ERROR",L"error",NULL);
}
return 1;
}





CreateBuffer(g_pVertexBuffer2, vertices,sizeof(SimpleVertex)*6);


It crashes at the line where the buffer is accesed by IASetVertexBuffers

Share this post


Link to post
Share on other sites
Advertisement
Your function looks correct to me. It creates successfully afterall!

Are you sure you use IASetVertexBuffers correctly? Edited by Ripiz

Share this post


Link to post
Share on other sites
Yes, when I create the buffer in the main function (as the code above) it works. When I drop the buffer in the CreateBuffer function it doesnt work; Edited by Papadopol

Share this post


Link to post
Share on other sites
Oh. I misunderstood you in original post. Function declaration should be

int D3Device11::CreateBuffer(ID3D11Buffer** dx11_buffer, SimpleVertex *data, int ByteWidth); // double pointer is a must

Share this post


Link to post
Share on other sites
Ok, it worked! :D
But why double pointer ? Because the buffer is not created as an object ? Can you explain please ?
Thank you.

Share this post


Link to post
Share on other sites
Now I'm having problems accesing a buffer withing a function where a initiate a vertex shader.

CreateShader(LPCWSTR file_name,
LPCSTR vertexshader, LPCSTR pixelshader,
ID3D10Blob** vertexShaderBuffer, ID3D10Blob** pixelShaderBuffer,
ID3D10Blob** errorMessage) {


// I Succesfully Compile the shader
// But I cant acces the buffer's parameters to Create the pixel shader

//crash at CreateVertexShader seems I cannot acces the buffer with (*buffer)->data way
hr = g_pDevice->CreateVertexShader( (*vertexShaderBuffer)->GetBufferPointer(), (*vertexShaderBuffer)->GetBufferSize(),
NULL, &g_pVertexShader );


(*vertexShaderBuffer)->GetBufferPointer() and (*vertexShaderBuffer)->GetBufferPointer() are accesed corectly ? Edited by Papadopol

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!