Jump to content
  • Advertisement
Sign in to follow this  
Quat

XNA::AxisAlignedBox

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a class that has data member:

std::vector<XNA::AxisAlignedBox> boxes;

I am getting error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned

Is there a way to have a vector of XNA::AxisAlignedBox?

Share this post


Link to post
Share on other sites
Advertisement
some of the xna data types can't be stored into arrays or vectors, data types like xmvector and xmmatrix. I had a really good link that explained exactly why, but i can't seem to find it now. but the idea is that when doing calculations with these, each of the components get their own thread to do the processing. I can't remember the details, but I'm afraid you might be out of luck, probably because AxisAlignedBox uses one of the xna data types like xmvector.


just found the link:
http://www.asawicki.info/news.php5?x=tag&tag=directx

Share this post


Link to post
Share on other sites
The problem is that XNA::AxisAlignedBox (and XMVECTOR) has alignment requirements, which VC's std::vector does not support by default.
The reason you're getting an error is because vector's resize (I think) is taking a parameter by value, which VC does not support for aligned types (or something along those lines).

There are a few solutions to this, such as editing that one function in <vector> to take its parameter by const reference instead of value (double click on your error to find the exact line it's on), or using a different dynamic array, such as btAlignedObjectArray.

If you go with the header editing solution, you're going to need an STL compatible allocator which supports aligned allocations. The easiest way to make this is making a class which derives from std::allocator, and simply override allocate and deallocate functions with _aligned_malloc and _aligned free.
You can use aligned objects in a vector with the default STL allocator (it will compile just fine). However, the elements will not be guaranteed to be aligned properly, so your program will likely end up crashing about 75% of the time if you do this (the last 25% is you getting lucky and the elements just happened to get aligned to 16-byte boundaries). Not a good plan.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!