Bug fix for btSimpleBroadphase

ole.k
Posts: 17
Joined: Thu Jun 12, 2008 1:32 pm

Bug fix for btSimpleBroadphase

Post by ole.k »

btSimpleBroadphase uses a linked list for the list of allocated handles. This is OK as long as one does not free a handle. But if a handle is freed and has a predecessor in the linked list, the predecessor's link to the next allocated handle cannot be update as the predecessor is not known. A solution is to use a doubly linked list:

Code: Select all

28a29,30
> 	int			m_prevAllocated;
47a50,52
> 	SIMD_FORCE_INLINE void SetPrevAllocated(int prev) {m_prevAllocated = prev;}
> 	SIMD_FORCE_INLINE int GetPrevAllocated() const {return m_prevAllocated;}
> 
71a77,81
> 		m_pHandles[freeHandle].SetPrevAllocated(-1);
> 		if (m_firstAllocatedHandle >= 0)
>     {
> 			m_pHandles[m_firstAllocatedHandle].SetPrevAllocated(freeHandle);
>     }
87c97,111
< 		m_firstAllocatedHandle = proxy->GetNextAllocated();
---
> 		int next = proxy->GetNextAllocated();
> 		int prev = proxy->GetPrevAllocated();
> 		if (next >= 0)
> 		{
> 			m_pHandles[next].SetPrevAllocated(prev);
> 		}
> 		if (prev >= 0)
> 		{
> 			m_pHandles[prev].SetNextAllocated(next);
> 		}
> 		else
> 		{
> 			m_firstAllocatedHandle = next;
> 		}
> 
88a113
> 		proxy->SetPrevAllocated(-1);
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bug fix for btSimpleBroadphase

Post by Erwin Coumans »

btSimpleBroadphase uses a linked list for the list of allocated handles.
It shouldn't and we just removed this list, and fixed the code.

btSimpleBroadphase is a slow brute-force broadphase, just for testing purposes. So in most cases we recommend using btDbvtBroadphase or bt32BitAxisSweep3/btAxisSweep3.

Thanks for the report,
Erwin