potential alignment error with btVector3

Post Reply
Neurone
Posts: 7
Joined: Mon May 18, 2015 3:45 pm

potential alignment error with btVector3

Post by Neurone »

I'd like to store some objects in a vector. Each object is composed in turn of other objects, one of which has a btVector3 member.

On program start (probably somewhere in the constructor), line 674 of btvector3.h crashes with the following exception:
Unhandled exception at 0x01230C67 in application.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF.
The line is:
mVec128 = (__m128)_mm_xor_ps(mVec128, mVec128);

This happens whether i'm using either of the following to store the objects:
std::vector<Entity, boost::alignment::aligned_allocator<Entity, 16> > entities;
btAlignedObjectArray<Entity> entities;

The crashes don't happen all the time, perhaps only half the time. currently running a debug build, application compiled with visual studio 2013 update 4. How can i fix this problem? I wonder if this is even a problem with things not being properly aligned, or a different issue entirely?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: potential alignment error with btVector3

Post by Basroil »

Sounds like an out of bounds error (0xffffffff often comes from Array[-1]), so perhaps your btAlignedObjectArray is trying to access the "back" of an empty array?

Could be an alignment error, but unlikely if you are using btAlignedObjectArray
Neurone
Posts: 7
Joined: Mon May 18, 2015 3:45 pm

Re: potential alignment error with btVector3

Post by Neurone »

I've isolated the problem somewhat. I've wrapped all the physics related functionality in a physics class, which all entities have. The act of declaring an entity like Entity ent; causes the crashes. I've tried ATTRIBUTE_ALIGNED16(Entity), ATTRIBUTE_ALIGNED16(Physics), etc all to no avail. So it definitely isn't anything related to array out of bounds, its something else.
Neurone
Posts: 7
Joined: Mon May 18, 2015 3:45 pm

Re: potential alignment error with btVector3

Post by Neurone »

The problem doesn't seem to occur on release builds, which is odd.

After disabling all SSE2 functionality, I'm still having the same access violation error, except that the debugger points me to line 94 of the create rigid body function instead:
m_deltaAngularVelocity.setZero();

When I create a body, I assigned it to a shared_ptr using the make_shared macro. Converting that to just a raw unmanaged pointer seems to solve the problem.

Its concerning that i'm seeing so many errors. I really want to use Bullet, but I can't if its so unstable for me.
Post Reply