简体   繁体   中英

c++ Directx 11 Devicecontext error when rendering custom model

Whenever I try to render a custom model in my program the program crashes When I try to run it in debug mode it points me to

deviceContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);

The odd thing is that I have two different models stored in two different files. The first model renders all file with no problems this is also the more "advanced" model, but now I'm trying to render a box, a very simple box. But whenever I try to render this box my programs crashes and ends up on that line. And I dont know what I'm doing wrong, or what can cause it.

I whould like to know what could make this "IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);" crash

First of all, Make sure you have initialized DirectX properly. If you have done that and the ID3D11DeviceContext works properly I use this folowing code.

MyStructure:

struct D3D11TextureVertexType
{
    XMFLOAT3 Position;
    XMFLOAT2 TX;
};

Part of my Function that uses deviceContext->IASetVertexBuffers..

hr = m_pd3dImmediateContext->Map(MyID3D11Buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(hr)) return hr;

pData = (D3D11TextureVertexType*)mappedResource.pData;
memcpy(pData, MYOBJECTVERTICES/*this is D3D11TextureVertexType*/, sizeof(D3D11TextureVertexType) * VertexCount);

m_pd3dImmediateContext->Unmap(MyID3D11Buffer, 0);

stride = sizeof(D3D11TextureVertexType);
offset = 0;

m_pd3dImmediateContext->IASetVertexBuffers(0, 1, &MyID3D11Buffer, &stride, &offset);
m_pd3dImmediateContext->IASetIndexBuffer(m_AdjRectangleIBuffer, DXGI_FORMAT_R32_UINT, 0);
m_pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

result = m_TextureShader->Render(m_pd3dImmediateContext, 6, worldMatrix, viewMatrix, orthoMatrix, m_Textures[Q.textureID]->pSRV);           if (!result)
{
    return S_FALSE;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM