I’m making pong in DirectX11 and I’m getting some weird error.
I have a pointer declared inside my Pong class:
XMVECTOR *ballDirection;
And for some reason, whenever I try to access it:
Unhandled exception at 0x002127d8 in DirectX11Pong.exe:
0xC0000005: Access violation reading location 0x00000000.
I’m pretty sure this is what happens when you try to access a nullptr pointer, but,
before any “accessing” to the pointer happens, I have it initialized:
ballDirection = new XMVECTOR();
For example, the line of code right now I’m getting this error at is the following:
*ballDirection = XMVectorSetX(*ballDirection, 1);
The only other information that I think is relevant is that I tried earlier to turn a single pointer that holds the paddle info into an array of pointers (for multiple players):
(Before)
Sprite *paddle;
(After)
Sprite *paddle[2];
The moment I did this, I got this error accessing ballDirection,
even though it worked perfectly before I made this array, and I changed no code to do with ballDirection while creating the array and modifying the appropriate code.
After I noticed getting this error I changed the code back, and this still happened.
How can I fix this?
Microsoft does say about dynamic allocation of
XMVECTORthat:So you should not just
new XMVECTORthere and expect that all works.