btDiscreteDynamicsWorld 16 aligned

Post Reply
Tau
Posts: 25
Joined: Tue May 01, 2012 11:52 am

btDiscreteDynamicsWorld 16 aligned

Post by Tau »

I'm using bullet physics for a longer time. I always used it in MS Visual Studio 2010. For a while i downloaded MS Visual Studio 2013. It took a while to set it up, but now i can use bullet in 2013 as well. But now, when i build my project i get warning:
warning C4316: 'btCollisionDispatcher' : object allocated on the heap may not be aligned 16
warning C4316: 'btDiscreteDynamicsWorld' : object allocated on the heap may not be aligned 16
Why haven't i got this warning in 2010? Do i really have to align them? I tried to put:

Code: Select all

	void* operator new(size_t i)
	{
		return _mm_malloc(i, 16);
	}

	void operator delete(void* p)
	{
		_mm_free(p);
	}
inside btDiscreteDynamicsWorld and btCollisionDispatcher but then my application crashed with assertion _BLOCK_TYPE_IS_VALID(pHead->nBlockUse).
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: btDiscreteDynamicsWorld 16 aligned

Post by c6burns »

If you don't ensure 16 byte alignment ... it is possible that Bad Things(tm) could happen when instructions expecting 16 byte alignment operate on the data. (SSE instruction operating on misaligned data)

Either allocate on the stack, or you can use the macros in bullet for this:

Code: Select all

ATTRIBUTE_ALIGNED16(class) MyPhysicsWrapper
{
public:
    BT_DECLARE_ALIGNED_ALLOCATOR();

    // pointers to bullet things you will heap alloc
}
If you google this you will find a lot of discussion on this topic
Tau
Posts: 25
Joined: Tue May 01, 2012 11:52 am

Re: btDiscreteDynamicsWorld 16 aligned

Post by Tau »

Thanks for the tip, i used BT_DECLARE_ALIGNED_ALLOCATOR(); but now, when i delete this class i get assertion failure _BLOCK_TYPE_IS_VALID(pHead->nBlockUse).
c6burns
Posts: 149
Joined: Fri May 24, 2013 6:08 am

Re: btDiscreteDynamicsWorld 16 aligned

Post by c6burns »

You are probably doing something wrong with pointers / references / double free. Debug your code very closely, this is not a bullet related issue it's a memory management related one. The debugger is your friend. Google for examples on how this happens.
Post Reply