btDbvtBroadphase::rayTest causes memory allocations

Post Reply
kFactor
Posts: 2
Joined: Wed Oct 01, 2014 6:02 pm

btDbvtBroadphase::rayTest causes memory allocations

Post 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
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: btDbvtBroadphase::rayTest causes memory allocations

Post 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
kFactor
Posts: 2
Joined: Wed Oct 01, 2014 6:02 pm

Re: btDbvtBroadphase::rayTest causes memory allocations

Post by kFactor »

Excellent!
Thanks
Post Reply