vector.size() instead of literal type breaking my draw code

SirYakalot
  • vector.size() instead of literal type breaking my draw code SirYakalot

    I'm writing a simple class to draw all the debugging lines I have in my scene at once.

    The code in the draw loop is this so far: (If I put for example, 2 instead of temporary2DVerts.size() where I have marked with //THIS LINE, the code works fine.) when I run the code below the line breaks //HERE. Access violation reading location 0x00000000. seems like the create buffer line is not working, but why? what's the solution?

    D3D10_BUFFER_DESC bd;
    bd.Usage = D3D10_USAGE_DYNAMIC;
    bd.ByteWidth = sizeof(VERTEX) * temporary2DVerts.size();// THIS LINE
    bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
    bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
    bd.MiscFlags = 0;
    
    device->CreateBuffer(&bd, NULL, &pBuffer);
    
    void* pVoid;
    
    pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); //HERE
    memcpy(pVoid, &temporary2DVerts[0], sizeof(temporary2DVerts[0]) * temporary2DVerts.size());
    pBuffer->Unmap();
    
        device->IASetInputLayout(screenVertexLayout);
    
        device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);
    
        UINT stride = sizeof(VERTEX);
        UINT offset = 0;
        device->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset);
    
        screenPass->Apply(0);
    
        device->Draw(temporary2DVerts.size(), 0);
    
        temporary2DVerts.clear();
    

  • It is very likely that device->CreateBuffer is failing, resulting in pBuffer being NULL. You need to check the return value.

Tags
c++ directx directx10
Related questions and answers
  • ) * 8; bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device->CreateBuffer(&bd, NULL, &pBuffer); void* pVoid; // the void pointer pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the vertex buffer memcpy(pVoid, OurVertices, sizeof(OurVertices)); // copy the vertices to the buffer pBuffer->Unmap..._WRITE; bd.MiscFlags = 0; device->CreateBuffer(&bd, NULL, &pBuffer); void* pVoid; // the void pointer pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the vertex buffer

  • : temp2DVerts.size(); bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device->CreateBuffer(&bd, NULL, &pBuffer); void* pVoid; // the void pointer pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the vertex buffer memcpy(pVoid, &temporary2DVerts[0], sizeof(temporary2DVerts[0..., &pBuffer, &stride, &offset); // apply the appropriate pass screenPass->Apply(0); // draw the vertex buffer to the back buffer device->Draw(temporary2DVerts.size

  • }, }; // create the vertex buffer D3D10_BUFFER_DESC bd; bd.Usage = D3D10_USAGE_DYNAMIC; bd.ByteWidth = sizeof(VERTEX) * 8; bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device->CreateBuffer(&bd, NULL, &pBuffer); void* pVoid; // the void pointer pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the vertex buffer...; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device->CreateBuffer(&bd, NULL, &iBuffer); iBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the index buffer memcpy

  • UINT stride = sizeof(LINE); UINT offset = 0; device->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset); device->IASetIndexBuffer(iBuffer, DXGI_FORMAT_R32_UINT, 0); allLines... UINT stride = sizeof(VERTEX); UINT offset = 0; device->IASetVertexBuffers(0, 1, mesh.PBuffer(), &stride, &offset); device->IASetIndexBuffer(mesh.IBuffer(), DXGI_FORMAT_R32_UINT, 0...); pRotation->SetMatrix(&temporaryLines[i].rotation._11); // set the rotation matrix in the effect pPass->Apply(0); device->DrawIndexed(2, 0, 0); } temporaryLines.clear

  • ; bd.ByteWidth = sizeof(VERTEX) * 8; bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device->CreateBuffer(&bd, NULL, &pBuffer); void* pVoid; // the void pointer pBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the vertex buffer memcpy(pVoid, OurVertices, sizeof(OurVertices)); // copy the vertices to the buffer... = D3D10_USAGE_DYNAMIC; bd.ByteWidth = sizeof(DWORD) * 36; bd.BindFlags = D3D10_BIND_INDEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; device->CreateBuffer(&bd, NULL

  • matView, D3DXMATRIX matProjection) { device->IASetInputLayout(pVertexLayout); device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP); // select which vertex buffer and index buffer to display UINT stride = sizeof(LINE); UINT offset = 0; device->IASetVertexBuffers(0, 1, &pBuffer, &stride, &offset); device->IASetIndexBuffer(iBuffer, DXGI...I have a class which "collects" line mesh transformations throughout the update and then draws them in one place by drawing one line over and over again. I'll post the code below. I'm just wondering

  • ); glDisableClientState( GL_COLOR_ARRAY ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); } Back to the Vertex Array Object though. My code for creating the Vertex... onscreen, in the shape of the terrain rectangle, but there are no regular lines etc. Here's the code I use for rendering: void ShaderProgram::Draw() { using namespace AntiMatter; if( ! m... into a shader program, for use with glDrawArrays. My vertex data already exists in a VertexBufferObject that uses the following data structure to create a vertex buffer: class CustomVertex { public

  • , Info.Format, D3DPOOL_SYSTEMMEM, &Surface, NULL); D3DXLoadSurfaceFromFile(Surface, NULL, NULL, wsPath.c_str(), NULL, D3DX_FILTER_NONE, 0, NULL); pd3dDevice -> GetBackBuffer(0, 0..._VERTEXPROCESSING, &d3dpp, &pd3dDevice))) return false; return true; } void render(void) { // check to make sure you have a valid Direct3D device if (NULL == pd3dDevice) return; pd3dDevice -> Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0); // clear the back buffer to a blue color if (SUCCEEDED(pd3dDevice -> BeginScene

  • I have a MD2 model loader, I am trying to substitute its immediate drawing function with a Vertex Buffer Object one.... I am getting a really annoying access violation reading error and I can't...->texCoordY); glVertex3f(pos[0], pos[1], pos[2]); } } glEnd(); What I'd like to do is to calculate all positions before hand, store them in a Vertex array and then draw..._template_1.exe: 0xC0000005: Access violation reading location 0xed5243c0" pointing at line 7 Vec3f pos = v1->pos * (1 - frac) + v2->pos * frac; where the two Vs seems to have no value

Data information