Hello, I'm trying to render a .obj exported from blender. In my code I transpose the world, view and projection matrices, but as soon as I try to transpose the world matrix, I get a "Unhandled exception at 0x003EDF63 in Obj Renderer.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF." This is odd cause the code is pretty much the same as in other projects which work.
[source lang="cpp"]deviceContext->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
deviceContext->ClearRenderTargetView(renderTargetView, &clearColor.x);
ConstantBuffer cb;
cb.world = DirectX::XMMatrixTranspose(world);
cb.view = DirectX::XMMatrixTranspose(view);
cb.proj = DirectX::XMMatrixTranspose(proj);
deviceContext->UpdateSubresource(cBuf, 0, nullptr, &cb, 0, 0);
deviceContext->VSSetConstantBuffers(0, 1, &cBuf);
UINT vertexCount = cylinder->meshes.front().vn.size();
deviceContext->Draw(vertexCount, 0);
swapChain->Present(0, 0)[/source]
The problem is that sometimes this will compile and execute, but nothing will render, and sometimes it'll throw an exception. I have the matrices set up as
[source lang="cpp"]void Model::build_matrices()
{
auto e = XMVectorSet(0.0f, 0.0f, -3.0f, 1.0f);
auto u = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
auto t = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f);
view = DirectX::XMMatrixLookAtLH(e, t, u);
world = DirectX::XMMatrixTranslation(0.0f, 0.0f, 2.0f);
proj = DirectX::XMMatrixPerspectiveFovLH(XM_PIDIV2, aspect_ratio(), 0.1f, 1000.0f);
}[/source]
with view, world, proj declared as DirectX::XMMATRIX. Can someone please help - this is baffling
XMMatrixTranspose Crashes
the destination of XMMatrix* ops needs to be 16-byte aligned when compiled with SSE(2) enabled, else you are gonna go to crash heaven (or worse, crash your GFX driver....)
Try making a temporary stack allocated XMMMatrix and then memcpy from that into your view/world/proj
Try making a temporary stack allocated XMMMatrix and then memcpy from that into your view/world/proj
In case you need it, here's how you convert between XMMATRIX and XMFLOAT4X4 (so that you can use the XNA functions)
XMLoadFloat4x4()
XMStoreFloat4x4
XMLoadFloat4x4()
//transpose to feed to shader
shaderData cbd;
cbd.world = XMMatrixTranspose(XMLoadFloat4x4(&m_world));
cbd.view =XMMatrixTranspose(XMLoadFloat4x4(&p_camera.getView()));
cbd.projection =XMMatrixTranspose(XMLoadFloat4x4(&p_camera.getProjection()));
XMStoreFloat4x4
XMMATRIX world = XMMatrixRotationY(p_deltaTime);
XMStoreFloat4x4(&m_world, world);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement