Last active
February 12, 2018 14:16
-
-
Save marukun318/f204846fb1a34ee47877bce0c460e77e to your computer and use it in GitHub Desktop.
DirectX11 Bad Knouhow: VertexBuffer / IndexBuffer Write
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ID3D11Buffer* m_pVertexBuffer; | |
ID3D11Buffer* m_pIndexBuffer; | |
// | |
D3D11_MAPPED_SUBRESOURCE msr = {}; | |
HRESULT hr; | |
// vertices upload | |
hr = m_context->Map(m_pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &msr); | |
if (FAILED(hr)) | |
return; | |
memcpy_s(msr.pData, sizeof(vtx_buf), vtx_buf, msr.RowPitch); // 頂点コピー msr.RowPitchで全体を書き換えないとまれに落ちる | |
m_context->Unmap(m_pVertexBuffer, 0); | |
// indices upload | |
D3D11_MAPPED_SUBRESOURCE ires = {}; | |
hr = m_context->Map(m_pIndexBuffer 0, D3D11_MAP_WRITE_DISCARD, 0, &ires); | |
if (FAILED(hr)) | |
return; | |
void* idxbuf = ires.pData; | |
if (idxbuf) { | |
// memcpy(idxbuf, idc_buf, sizeof(uint32_t) * m_idc_cnt); // 書き換えたインデックス数のコピーだとまれに落ちる | |
memcpy_s(idxbuf, sizeof(idc_buf), idc_buf, ires.RowPitch); // msr.RowPitchで全体を書き換えないと落ちる | |
m_context->Unmap(m_pIndexBuffer, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment