Jump to content

  • Log In with Google      Sign In   
  • Create Account


Thomas Vandenberghe

Member Since 27 Mar 2013
Offline Last Active Apr 11 2013 03:34 PM
-----

Topics I've Started

xnamath byte alignment

27 March 2013 - 07:46 AM

I've come across this problem while following Beginning DirectX 11 Game Programming. During the cube demo the view and projection matrix are being transposed. If I'm using local XMMatrix as the parameter it works fine, if I'm using the member variable however it crashes with the error:

Unhandled exception at 0x00D4F279 in DX11Project.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF.

 

I've come upon a few answers where they state XMMatrix expects objects which are 16-byte aligned and some objects created would be 8-byte aligned which would cause the crash.

 

Has anyone else come across this sort of problem, and would there be any way to fix it without creating local variables?

 

 

 

The member variables are declared in Cube.h

class Cube : public DX11Base
{
//...
XMMATRIX	m_viewMatrix;
XMMATRIX	m_projMatrix;
//...
};

 

The code crashes when I'm using:

m_viewMatrix = XMMatrixIdentity();
m_projMatrix = XMMatrixPerspectiveFovLH(XM_PIDIV4, 800.0f/600.0f, 0.01f, 100.0f);

m_viewMatrix = XMMatrixTranspose(m_viewMatrix);
m_projMatrix = XMMatrixTranspose(m_projMatrix);

 

It works fine when I'm using:

XMMATRIX view(XMMatrixIdentity());
XMMATRIX proj(XMMatrixPerspectiveFovLH(XM_PIDIV4, 800.0f/600.0f, 0.01f, 100.0f));

m_viewMatrix = XMMatrixTranspose(view);
m_projMatrix = XMMatrixTranspose(proj);

 

Edit: I just found that by defining _XM_NO_INTRINSICS_ in your preprocessor also makes it work, however this will disable the optimization:

_XM_NO_INTRINSICS_ defines that no intrinsic types are to be used and that the XNA Math library will only use standard floating-point precision when performing its operations. This can be seen as the behavior that will allow an application to use XNA Math with no special optimizations or functionality.


PARTNERS