Jump to content
  • Advertisement
Sign in to follow this  

DX11 Invalid argument when mapping a dynamic vertex buffer

This topic is 2073 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. I'm writing a render loop in DX11 which should process a couple of characters, one at a time. 
i am using a dynamic vertex buffer, and i have specified for this buffer that the CPU can write to 
it. Normally i should use D3D11_MAP_WRITE when mapping, but this results in an invalid argument. 
i tried setting the CPU flags to WRITE and READ, but then the first creation of the buffer fails with 
invalid argument.
i have this in loadcontent:
  D3D11_BUFFER_DESC vertexDesc;
    ZeroMemory( &vertexDesc, sizeof( vertexDesc ) );
    vertexDesc.Usage = D3D11_USAGE_DYNAMIC;
    vertexDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    const int sizeOfSprite = sizeof( VertexPos ) * 6;  //one sprite is one letter
    const int maxLetters = 24;
    vertexDesc.ByteWidth = sizeOfSprite * maxLetters;
    d3dResult = d3dDevice_->CreateBuffer( &vertexDesc,0, &vertexBuffer_ );
and this in render
for (int i = 0; i < TextRenderClass_->GetNumChars(); i++)
TextRenderClass_->CalcFontSprite(i, p, uv);//calculates positions, works well!
TextRenderClass_->GetChar(i, c);//get the actual character
DrawChar(c, p, uv, i); 
and this in drawChar:
  // Size in bytes for a single sprite.
    const int sizeOfSprite = sizeof( VertexPos ) * 6;
   // verts per-triangle (3) * total triangles (2) = 6.
    const int verticesPerLetter = 6;
    D3D11_MAPPED_SUBRESOURCE mapResource;
    HRESULT d3dResult = d3dContext_->Map( vertexBuffer_,0, D3D11_MAP_WRITE, 0, &mapResource );
   if( FAILED( d3dResult ) )
        //when using MAP_WRITE i get an invalid argument here. not when using MAP_DISCARD
        DXTRACE_MSG( "Failed to map resource!" );
        return false;
    // Point to our vertex buffer's internal data.
    VertexPos *spritePtr = ( VertexPos* )mapResource.pData;
int offset = 6 * i;
spritePtr += offset;
spritePtr[0].pos = XMFLOAT3( p.thisEndX,   p.thisEndY, 1.0f );
    spritePtr[1].pos = XMFLOAT3( p.thisEndX,   p.startY,   1.0f );
spritePtr[2].pos = XMFLOAT3( p.thisStartX, p.startY,   1.0f );
    spritePtr[3].pos = XMFLOAT3( p.thisStartX, p.startY,   1.0f );
    spritePtr[4].pos = XMFLOAT3( p.thisStartX, p.thisEndY, 1.0f );
spritePtr[5].pos = XMFLOAT3( p.thisEndX,   p.thisEndY, 1.0f );
spritePtr[0].tex0 = XMFLOAT2( uv.tuEnd, 0.0f );
    spritePtr[1].tex0 = XMFLOAT2( uv.tuEnd, 1.0f );
    spritePtr[2].tex0 = XMFLOAT2( uv.tuStart, 1.0f );
    spritePtr[3].tex0 = XMFLOAT2( uv.tuStart, 1.0f );
    spritePtr[4].tex0 = XMFLOAT2( uv.tuStart, 0.0f );
    spritePtr[5].tex0 = XMFLOAT2( uv.tuEnd, 0.0f );
    d3dContext_->Unmap( vertexBuffer_, 0 );
d3dContext_->Draw(6, offset);
can anyone help me?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!