Jump to content
  • Advertisement
Sign in to follow this  
Thomas Vandenberghe

xnamath byte alignment

This topic is 2062 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

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.

Edited by Thomas Vandenberghe

Share this post

Link to post
Share on other sites

You can use local variables, or you can make sure that Cube is always 16 byte aligned by using a custom allocator.


If you can't guarantee the alignment, the safest way would be to use XMFLOAT4X4 in the class and explicitly load and store to XMMATRIX when needed.

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!