16 byte alignment issue in vector< btVector3 >

Post Reply
loefje
Posts: 18
Joined: Thu May 28, 2009 10:43 am

16 byte alignment issue in vector< btVector3 >

Post by loefje »

Hi there,

I'm having trouble creating a std::vector< btVector3 >, because of alignment issues,
even though my project settings ( MSVC2008, WinXP ) are set for 16 byte alignment..
Does anyone know how to get around this problem ? I'm not too familiar with structure alignment issues..

TIA,

Jochem van der Spek

Ps the error from MSVC reads:

1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector(717) : error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned
1> ..\..\src\Main.cpp(684) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1> with
1> [
1> _Ty=Types::Vector3
1> ]

I have simply typedef'd btVector3 to my namespace Types::Vector3. which isn't the issue,
because this fails with std::vector< btVector3 > too..
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: 16 byte alignment issue in vector< btVector3 >

Post by Dirk Gregorius »

I think this was discussed in the forum already. The fastest workaround is using STLport instead of the Dinkumware STL implementation that ships with Visual Studio. It does not suffer from this problem.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: 16 byte alignment issue in vector< btVector3 >

Post by Erwin Coumans »

Bullet uses btAlignedObjectArray as std::vector replacement due to the buggy Microsoft STL implementation.

But if you want a more fancy and full featured stl implementation, Dirk's suggestion, STL Port could do.
Thanks,
Erwin
loefje
Posts: 18
Joined: Thu May 28, 2009 10:43 am

Re: 16 byte alignment issue in vector< btVector3 >

Post by loefje »

Hi, thanks for the answers & sorry for the late reply.

loefje
sipickles
Posts: 44
Joined: Thu Aug 07, 2008 6:57 am

Re: 16 byte alignment issue in vector< btVector3 >

Post by sipickles »

I am having a similar issue.

I am using boost::python to wrap c++ classes which use Bullet. If any class contains a btVector3 member, it will not compile, or if I try to expose btVector3 as a boost::python object.

Here's the result:

Code: Select all

C:\boost_1_38_0\boost/python/converter/as_to_python_function.hpp(21) : error C2719: 'unnamed-parameter': formal parameter with __declspec(align('16')) won't be aligned
        C:\boost_1_38_0\boost/python/to_python_converter.hpp(88) : see reference to class template instantiation 'boost::python::converter::as_to_python_function<T,ToPython>' being compiled
        with
        [
            T=btVector3,

            [snip]
I gather this is because of the btAlignmentAllocator used by btVector3. When boost::python exposes a c++ object to python it passes by value.

I've even tried stlport but this has no effect.

Is there anyway I can define-out the use of btAlignmentAllocator and suffer the performance penalties? Meanwhile I will try to find out how to pass-by-ref in boost::python.

Thanks

Simon
loefje
Posts: 18
Joined: Thu May 28, 2009 10:43 am

Re: 16 byte alignment issue in vector< btVector3 >

Post by loefje »

hi again,

I'm having some trouble with the btAlignedObjectArray,
when I'm returning one from a function, after some swapping,pushing, etc.
my code crashes in aligned_free_dbg. I have no idea what's going on.
I dont have dynamic data allocation going on, so I wonder if it's a bug
in btAlignedObjectArray. (see linked image at www.dynamica.org/PUB/crash.jpg )

I hope anyone can shed some light on this issue.

TIA,

jochem van der Spek

Image
ngbinh
Posts: 117
Joined: Fri Aug 12, 2005 3:47 pm
Location: Newyork, USA

Re: 16 byte alignment issue in vector< btVector3 >

Post by ngbinh »

sipickles wrote:I am having a similar issue.

I am using boost::python to wrap c++ classes which use Bullet. If any class contains a btVector3 member, it will not compile, or if I try to expose btVector3 as a boost::python object.

Here's the result:

Code: Select all

C:\boost_1_38_0\boost/python/converter/as_to_python_function.hpp(21) : error C2719: 'unnamed-parameter': formal parameter with __declspec(align('16')) won't be aligned
        C:\boost_1_38_0\boost/python/to_python_converter.hpp(88) : see reference to class template instantiation 'boost::python::converter::as_to_python_function<T,ToPython>' being compiled
        with
        [
            T=btVector3,

            [snip]
I gather this is because of the btAlignmentAllocator used by btVector3. When boost::python exposes a c++ object to python it passes by value.

I've even tried stlport but this has no effect.

Is there anyway I can define-out the use of btAlignmentAllocator and suffer the performance penalties? Meanwhile I will try to find out how to pass-by-ref in boost::python.

Thanks

Simon
You can remove #define BT_USE_SSE and change


//#define SIMD_FORCE_INLINE __forceinline
//#define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
//#define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
//#define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a
#define SIMD_FORCE_INLINE inline
#define ATTRIBUTE_ALIGNED16(a) a
#define ATTRIBUTE_ALIGNED64(a) a
#define ATTRIBUTE_ALIGNED128(a) a

then you should be fine.

Bullet is flexible enough I guess. But be warned, you will loose performance.
Post Reply