2

My Win32, DirectX game is crashing in release mode within code that is manipulating vectors and matrices. Specifically the crash occurs on this instruction:

014E2752 unpcklps xmm1,xmmword ptr [esp+3Ch]

First-chance exception at 0x014E2752 in RodinaRelease.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF

I'm not too experienced with digging into assembly and registers but it appears that esp = 0x0043f31c which would make esp+3Ch = 0x0043f358

Now, according to this and this, the unpcklps instruction is an SSE instruction which requires an alignment of 16 bytes. 0x0043f358 is NOT 16-byte aligned, correct? Am I right in thinking that the alignment of the stack is the cause of my crash?

If so, what did I do to deserve this???? I don't use SSE instructions in my game so I can ignore alignment issues like this - is that naive/wrong? Is there any way to turn this behavior off?

Relevant points:

  • I recently upgraded to Visual Studio 2013 and am suspicious that this bug appeared about this time. I found a bug report that is similar to my problem.

  • My game uses XNAMath, specifically XMMATRIX and XMVECTOR. Normally this would require that I align everything. However, because I didn't want to run into problems like this, I am compiling with the _XM_NO_INTRINSICS_ flag which is supposed to turn off XNAMath's use of SIMD instructions. That has never seemed to be an issue until now. The specific crash that I am dealing with is with my own vector type, but it is in close enough proximity to XMMATRIX code that I believe that it's all mixed together by optimizations.

  • My game is built as a Win32 application. Is switching to x64 a viable solution to this or would that be ridiculous overkill? I don't know what consequences that would have besides needing to get 64-bit versions of libraries I use.

Raptormeat
  • 283
  • 2
  • 11

1 Answers1

1

See this answer for more details.

Keep in mind that VS 2013 for x86 defaults to using /arch:SSE2 so even with _XM_NO_INTRINSICS_ defined, the compiler is going to use SSE/SSE2. For that reason, you should probably stop using _XM_NO_INTRINSICS_ and just get your code to use DirectXMath or XNAMath correctly.

That said, you can try building with /arch:IA32 to force Visual Studio to use old-school legacy x87 instead of SSE/SSE2...

Community
  • 1
  • 1
Chuck Walbourn
  • 28,931
  • 1
  • 45
  • 72
  • Thank you for this answer. Based on the MSVC bug report I noted in my post, where a user was having the same error as I was, without using the DirectX stuff, I decided that it was safer to simply disable SSE intrinsics for now. Performance was pretty much the same, so I'm going with it. ... ... ... ... ... ... ... ... the bug report in question: https://connect.microsoft.com/VisualStudio/feedback/details/808357/access-violation-due-to-stack-misalignment-resp-wrong-sse-code-generated – Raptormeat Jun 05 '15 at 22:17
  • 1
    Make sure you try VS 2013 Update 5 which has some compiler fixes. Ideally using both ``/arch:SSE2`` and the default intrinsics is the best option. You should also consider using the [SimpleMath](https://github.com/Microsoft/DirectXTK/wiki/SimpleMath) wrapper in the [DirectX Tool Kit](https://github.com/Microsoft/DirectXTK) since it hides some of the alignment fuss with DirectXMath in x86 (32-bit) apps. – Chuck Walbourn Aug 01 '15 at 01:42