Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


xnamath byte alignment


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Thomas Vandenberghe   Members   -  Reputation: 104

Like
0Likes
Like

Posted 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.


Edited by Thomas Vandenberghe, 27 March 2013 - 09:42 AM.


Sponsor:

#2 EWClay   Members   -  Reputation: 659

Like
0Likes
Like

Posted 27 March 2013 - 11:53 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS