I'm working on a DirectX application, and I'm having some trouble multiplying 2 matrices together, when i try to I get a run time error. I only get the error if i declared the matrices in my header, if i declare them locally in the function it works fine. This isn't the only place in the application where i get the this type of error.
GraphicClass.cpp
void GraphicClass::UpdateScene()
{
Cube1World = DirectX::XMMatrixIdentity();
DirectX::XMVECTOR rotaxis = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
Rotation = DirectX::XMMatrixRotationAxis(rotaxis, rot);
Translation = DirectX::XMMatrixTranslation(0.0f, 0.0f, 4.0f);
Cube1World = Translation * Rotation; //I get run time error on this line
}
GraphicClass.h
class GraphicClass{
DirectX::XMMATRIX Cube1World;
DirectX::XMMATRIX Rotation;
DirectX::XMMATRIX Translation;
float rot = 0.01f;
//other Code
}
Error Message
Unhandled exception at 0x002F4C0F in Engine.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF.
I'm able to declare Cube1World in the header file, but i if try to do it with either Rotation or Translation i get the run time error.
I'm running windows 8.1 with visual studio 2015 and the latest directx sdk. I hope i explained the problem well enough, thanks in advance.
I found the answer on this thread
Crash after m = XMMatrixIdentity() - aligment memory in classes?
"In the Book "Introduction to 3D Game Programming with Directx 11" from "Frank D. Luna" it says:
Do not use XMMATRIX as Member of a class or Structure. Always use XMFloat4x4 and load and store back if you need it. "