1

I'm trying to implement Pitch/Yaw for my Camera class in D3D, but my Pitch() function, throws a "Access Violation reading location 0x0000008C".

I googled a bit and saw I can't use XMVECTOR in a class/struct because of 16 bit alignment. However I already knew that and I double checked that it was declared as a XMFLOAT3 and it was!

The thing is, in all of my other function of the Camera class (like updating the view matrix, ...) throw no exception. It's just in that one function!

So, here's how I declare my class variable that makes the function to crash (although all my variables make it crash, and they are defined the same way):

XMFLOAT3 mRight;

Here's how I declare the Pitch function:

void Pitch(float a)
{
    //Here it makes my code crash
    XMMATRIX R = XMMatrixRotationAxis(XMLoadFloat3(&mRight), a);

    //Store and compute
    XMStoreFloat3(&mLook, XMVector3TransformNormal(XMLoadFloat3(&mLook), R));
    XMStoreFloat3(&mUp, XMVector3TransformNormal(XMLoadFloat3(&mUp), R));
}

I'm also using x86 as architecture, although x64 gives the exact same results (except the memory location :D). Neither I or the DirectXMath Library can access the x, y and z values of "mRight". In my case "mRight.x" in DirectXMath's case "__m128 x = _mm_load_ss( &pSource->x );".

Some new Debug results: This weirdly happens when I call 'any' function from my WM_MOUSEMOVE event. Even my function Walk(), which works perfectly when I call it when a key is pressed.

Weirdest thing ever!

Thanks for the help!

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
  • What is your target architecture? x86 or x64? If you're building for x86 then you can't assume 16-bit alignment for your variables. Also, it might be more helpful if you would step through your code with debugger to see exactly where the exception occurs. This is easy since DirectXMath is open-source. – rashmatash Sep 29 '14 at 15:21
  • My target architecture is x86, although x64 gives the same results. 2 Point: I actually did that, it happens when I (or DirectXMath) try to access the x,y,z position "mRight". In the DirectXMath case, it's in "__m128 x = _mm_load_ss( &pSource->x );" Thanks for your help btw – Rakete1111 Sep 29 '14 at 15:54

1 Answers1

0

I know my error!! I was giving an invalid pointer to my class that uses that code :D Fixed it

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
  • If you are going to use this pattern, you might want to look at using SimpleMath in the [DirectX Tool Kit](http://go.microsoft.com/fwlink/?LinkId=248929). – Chuck Walbourn Sep 30 '14 at 22:48