# Need some help, can't figure out what's wrong

This topic is 1427 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello!

Well I am stuck, I don¨t know why the following problem occurs. My program totally crashes once it is up, it says .... has stopped working. If I run the debug mode I get this message "Unhandled exception at 0x0088378B in D3.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF." and then I have to press break.

Now all this happens in the following code.

worldViewProj = worldMatrix * viewMatrix * projMatrix;
cbPerObj.WVP = DirectX::XMMatrixTranspose(worldViewProj);

Something is wrong with theese two or one of theese two particular lines, I can't figure out what it is. But it is here that the program breaks.



I didn¨t want to patste the whole code here but only to clarify where the problem occurs, below is a link to the whole project which you probably gonna have to look at but now you atleast know where the problem occurs

Regards!

##### Share on other sites

It likely has something to do with memory alignment, which is a common issue when working with DirectXMath objects and functions.  Can you describe the types of the objects you are using, and if you followed the declaration procedures listed here?

##### Share on other sites

Yes you are right here is the error I forgot to post,

1>c:\users\dawood\documents\visual studio 2013\projects\d3\d3\main.cpp(5): warning C4316: 'Ggraphics' : object allocated on the heap may not be aligned 16


I am a complete beginner sort of and don¨t know very much, I am following this tutorial. http://www.braynzarsoft.net/index.php?p=D3D11WVP

Also everything I have written in my entire project is in the link I posted to pastebin if you scroll up.

Edited by dawoodr

##### Share on other sites

Can anybody help me out? What should I change and how should I write it, please show it to me because I don't get it.

Regards!

##### Share on other sites

The XMMATRIX and XMVECTOR structures must be on 16 byte aligned boundaries. In the tutorial, all the XMMATRIX and XMVECTOR variables are in global scope. As a result, they would be aligned correctly.

You've declared your XMMATRIX and XMVECTOR variables as local (not global, as in the tutorial) in a class. When the class is created, as the warning indicates, there's no guarantee those structure will be aligned correctly (and they apparently are not!)

You can either declare them as global (i.e., not as class members), or use XMFLOAT4X4 and XMFLOAT3 (or XMFLOAT4) for needed matrices and vectors respectively.

For functions which require XMMATRIX and XMVECTOR parameters, use XMLoadFloat4x4 and XMLoadFloat3/4 to set the arguments, and XMStoreFloatxxx to store the results back in your variables.

Edited by Buckeye

##### Share on other sites

Ok I am trying to fix it but what does this mean "16 byte aligned boundaries" I don't even know what that is. And why do they have to be 16 byte aligned?

Also, would I have to have XMVECTOR and XMMATRIX aswell as XMFLOAT4 and XMFLOAT4X4 and then keep converting between them? Because I read that you should only do operations on XMVECTOR and XMMATRIX and for storing the variables or whatever you should use XMFLOATS, am I correct on this or wrong? Also if it is not too much to ask, could you take the code that I posted on pastebin and then take a row or two and remake them to show me? Meaning chaning a row or two where I am using the XMMATRIX and XMVECTOR and write them the correct what so the program works.

Regards!

Edited by dawoodr

##### Share on other sites
Try __declspec(align(16)) before every XMMATRIX or XMVECTOR.

##### Share on other sites

__declspec(align(16)) XMMATRIX World; ?

or
XMMATRIX
__declspec(align(16)) World; ?

If the problem occurs again I will definitely try this but I don't know WTF is wrong, the program just started working and all I did was rewrite the lines according to the tutorial I was following.

##### Share on other sites

They have the declspec on them already. The problem is that global operator new only gives you 8 byte aligned memory on Windows, so allocations will be misaligned about 50% of the time.

One standard fix is to replace global operator new and delete (and the various array and nothrow variants) and make them call _aligned_malloc() etc.

##### Share on other sites

Guys I really appreciate your help but since I am a newbie I really would appreciate some examples, meaning that you show me how to do it, it is very hard for me to understand otherwise. Please take your time to show me if you are able because the problem started occuring again

An example would be; If I want to allocate memory for my XMMATRIX WVP; how do I do it?

Regards!

Edited by dawoodr

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
frob
12

• 9
• 17
• 9
• 31
• 16
• ### Forum Statistics

• Total Topics
632617
• Total Posts
3007453

×