Visual C++ DirectX11 - Updating Dynamic Resource not working as expected
<p>I want to update the vertices of a DirectX11 ID3D11Buffer, but it is not working. I followed the guide <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dn508285(v=vs.85).aspx" rel="nofollow">How to use dynamic resources</a> from Microsoft.</p>

<p>This is my code for the buffer:</p>

<pre><code>// Create vertex buffer
int verticesAmount = 5;
pVertices = new XMFLOAT3[verticesAmount];
pVertices[0] = XMFLOAT3( -0.1f, -0.1f, 0 );
pVertices[1] = XMFLOAT3( -0.1f, 0.1f, 0 );
pVertices[2] = XMFLOAT3( 0.1f, 0.1f, 0 );
pVertices[3] = XMFLOAT3( 0.1f, -0.1f, 0 );
pVertices[4] = XMFLOAT3( -0.1f, -0.1f, 0 );

D3D11_BUFFER_DESC bd;
ZeroMemory( &amp;bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.ByteWidth = sizeof( XMFLOAT3 ) * verticesAmount;//sizeof(vertices);
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
bd.MiscFlags = 0;
bd.StructureByteStride = 0;

D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory( &amp;InitData, sizeof(InitData) );
InitData.pSysMem = pVertices;
InitData.SysMemPitch = 0;
InitData.SysMemSlicePitch = 0;

result = pDevice-&gt;CreateBuffer( &amp;bd, &amp;InitData, &amp;pLineStripBuffer )
</code></pre>

<p>This is my code when updating:</p>

<pre><code>//pVertices[2].x += 0.1f;  commented because I want to test whether it updates at all
D3D11_MAPPED_SUBRESOURCE mappedResource;
ZeroMemory(&amp;mappedResource, sizeof(D3D11_MAPPED_SUBRESOURCE));
//  Disable GPU access to the vertex buffer data.
pContext-&gt;Map(pLineStripBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &amp;mappedResource);
//  Update the vertex buffer here.
memcpy(mappedResource.pData, pVertices, 5);
//  Reenable GPU access to the vertex buffer data.
pContext-&gt;Unmap(pLineStripBuffer, 0)
</code></pre>

<p>This is what it looks like when the update code above is commented out:</p>

<p><a href="https://i.stack.imgur.com/BlfZx.png" rel="nofollow"><img src="https://i.stack.imgur.com/BlfZx.png" alt="enter image description here"></a></p>

<p>This is what is looks like uncommented:</p>

<p><a href="https://i.stack.imgur.com/3SFfy.png" rel="nofollow"><img src="https://i.stack.imgur.com/3SFfy.png" alt="enter image description here"></a></p>

<p>The screenshot of the updated buffer should be the same as the one above because the vertices didn't change positions.</p>