• Advertisement
Sign in to follow this  

XMMatrixTranspose Crashes

This topic is 2035 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 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);
with view, world, proj declared as DirectX::XMMATRIX. Can someone please help - this is baffling

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
Thank you very much. I couldn't figure out whythiswas happening. What an odd rule

Share this post

Link to post
Share on other sites
In case you need it, here's how you convert between XMMATRIX and XMFLOAT4X4 (so that you can use the XNA functions)


//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()));


XMMATRIX world = XMMatrixRotationY(p_deltaTime);
XMStoreFloat4x4(&m_world, world);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement