Page 1 of 1

16 byte alignment issue in vector< btVector3 >

Posted: Thu May 28, 2009 10:52 am
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..

Re: 16 byte alignment issue in vector< btVector3 >

Posted: Thu May 28, 2009 9:23 pm
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.

Re: 16 byte alignment issue in vector< btVector3 >

Posted: Thu May 28, 2009 9:26 pm
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

Re: 16 byte alignment issue in vector< btVector3 >

Posted: Mon Jun 15, 2009 8:31 am
by loefje
Hi, thanks for the answers & sorry for the late reply.

loefje

Re: 16 byte alignment issue in vector< btVector3 >

Posted: Wed Jun 24, 2009 12:27 pm
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

Re: 16 byte alignment issue in vector< btVector3 >

Posted: Sat Sep 12, 2009 9:39 pm
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

Re: 16 byte alignment issue in vector< btVector3 >

Posted: Sun May 02, 2010 6:32 am
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.