Page 1 of 1

btDbvtBroadphase::rayTest causes memory allocations

Posted: Wed Oct 01, 2014 7:13 pm
by kFactor
I have a relatively simple scene set up using btDiscreteDynamicsWorld, btSequentialImpulseConstraintSolver and btDbvtBroadphase.

Every frame I'm issuing a rayTest to the world to determine the ground height among other things.
However I'm noticing that the rayTest is doing temporary memory allocations, causing fragmentation and slowdowns.

The allocation itself occurs in btDbvt::rayTest when resizing a btAlignedObjectArray
(https://github.com/bulletphysics/bullet ... vt.h#L1034)

The call path during the allocation looks something like this

Code: Select all

btAlignedAllocInternal	btAlignedAllocator.cpp	163
btAlignedAllocator<btDbvtNode const*, 16u>::allocate	btAlignedAllocator.h	86
btAlignedObjectArray<btDbvtNode const*>::allocate	btAlignedObjectArray.h	105
btAlignedObjectArray<btDbvtNode const*>::reserve	btAlignedObjectArray.h	304
btAlignedObjectArray<btDbvtNode const*>::resize	btAlignedObjectArray.h	234
btDbvt::rayTest	btDbvt.h	1034
btCollisionWorld::rayTestSingleInternal	btCollisionWorld.cpp	556
btCollisionWorld::rayTestSingle	btCollisionWorld.cpp	269
btSingleRayCallback::process	btCollisionWorld.cpp	916
BroadphaseRayTester::Process	btDbvtBroadphase.cpp	223
btDbvt::rayTestInternal	btDbvt.h	998
btDbvtBroadphase::rayTest	btDbvtBroadphase.cpp	239
btCollisionWorld::rayTest	btCollisionWorld.cpp	931
Is there any way to configure Bullet to avoid causing these memory allocations?
In btDbvt there is a rayTestInternal function that could be used instead, but it is
not clear how that function could be called via btCollisionWorld::rayTest.

Thanks

Re: btDbvtBroadphase::rayTest causes memory allocations

Posted: Thu Oct 02, 2014 2:40 pm
by Erwin Coumans
We should fix that and allow pre-allocate this memory.

I created an issue for it, you can track progress here:
https://github.com/bulletphysics/bullet3/issues/254

Re: btDbvtBroadphase::rayTest causes memory allocations

Posted: Thu Oct 02, 2014 4:53 pm
by kFactor
Excellent!
Thanks