c++ - AccessViolation only in Optimised Win32 Build (XMMATRIX) -
i'm having problem setting 2 variables of type xmmatrix** in function. function prototype looks this:
bool viewportfactory::createviewport(canvashandle* canvashandleptr, viewporthandle** outviewporthandleptr, directx::xmmatrix** outprojectionmatrix, directx::xmmatrix** outviewmatrix) then, later on in function definition, have next 2 lines:
*outprojectionmatrix = new directx::xmmatrix(0.0f, 0.1f, /* ... */, 3.3f); *outviewmatrix = new directx::xmmatrix(0.0f, 0.1f, /* ... */, 3.3f); however, in win32 build optimisations turned on, lines give me access violation.
it's hard reason problem optimisations turned on, if alter lines set values nullptr, problem goes away.
this indeed alignment problem. new directx::xmmatrix in 32-bit programme 8-byte aligned, , xmmatrix must 16-byte aligned.
you can either utilize __aligned_malloc/__aliged_free instead of new or utilize xmfloat4x4 type instead. or rather allocating individual xmmatrix values heap, utilize stack-allocated xmmatrix instead aligned since xmmatrix marked __declspec(align(16)).
this covered in directxmath programmer's guide on msdn. it's not long document, , contains lots of advice.
c++ directx directxmath
No comments:
Post a Comment