Keep track of raw pointer returned from btAlignedAlloc when using placement new on an array.

This commit is contained in:
john.mccutchan
2008-08-07 16:02:59 +00:00
parent 7838a5c980
commit 551f0fa1ec
3 changed files with 13 additions and 9 deletions

View File

@@ -77,9 +77,11 @@ protected:
BP_FP_INT_TYPE m_numHandles; // number of active handles BP_FP_INT_TYPE m_numHandles; // number of active handles
BP_FP_INT_TYPE m_maxHandles; // max number of handles BP_FP_INT_TYPE m_maxHandles; // max number of handles
Handle* m_pHandles; // handles pool Handle* m_pHandles; // handles pool
void* m_pHandlesRawPtr;
BP_FP_INT_TYPE m_firstFreeHandle; // free handles list BP_FP_INT_TYPE m_firstFreeHandle; // free handles list
Edge* m_pEdges[3]; // edge arrays for the 3 axes (each array has m_maxHandles * 2 + 2 sentinel entries) Edge* m_pEdges[3]; // edge arrays for the 3 axes (each array has m_maxHandles * 2 + 2 sentinel entries)
void* m_pEdgesRawPtr[3];
btOverlappingPairCache* m_pairCache; btOverlappingPairCache* m_pairCache;
@@ -269,8 +271,9 @@ m_invalidPair(0)
m_quantize = btVector3(btScalar(maxInt),btScalar(maxInt),btScalar(maxInt)) / aabbSize; m_quantize = btVector3(btScalar(maxInt),btScalar(maxInt),btScalar(maxInt)) / aabbSize;
// allocate handles buffer and put all handles on free list // allocate handles buffer and put all handles on free list
void* ptr = btAlignedAlloc(sizeof(Handle)*maxHandles,16); m_pHandlesRawPtr = btAlignedAlloc(sizeof(Handle)*maxHandles,16);
m_pHandles = new(ptr) Handle[maxHandles]; m_pHandles = new(m_pHandlesRawPtr) Handle[maxHandles];
m_maxHandles = maxHandles; m_maxHandles = maxHandles;
m_numHandles = 0; m_numHandles = 0;
@@ -286,8 +289,8 @@ m_invalidPair(0)
// allocate edge buffers // allocate edge buffers
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
void* ptr = btAlignedAlloc(sizeof(Edge)*maxHandles*2,16); m_pEdgesRawPtr[i] = btAlignedAlloc(sizeof(Edge)*maxHandles*2,16);
m_pEdges[i] = new(ptr) Edge[maxHandles * 2]; m_pEdges[i] = new(m_pEdgesRawPtr[i]) Edge[maxHandles * 2];
} }
} }
//removed overlap management //removed overlap management
@@ -319,9 +322,9 @@ btAxisSweep3Internal<BP_FP_INT_TYPE>::~btAxisSweep3Internal()
for (int i = 2; i >= 0; i--) for (int i = 2; i >= 0; i--)
{ {
btAlignedFree(m_pEdges[i]); btAlignedFree(m_pEdgesRawPtr[i]);
} }
btAlignedFree(m_pHandles); btAlignedFree(m_pHandlesRawPtr);
if (m_ownsPairCache) if (m_ownsPairCache)
{ {

View File

@@ -50,8 +50,8 @@ btSimpleBroadphase::btSimpleBroadphase(int maxProxies, btOverlappingPairCache* o
} }
// allocate handles buffer and put all handles on free list // allocate handles buffer and put all handles on free list
void* ptr = btAlignedAlloc(sizeof(btSimpleBroadphaseProxy)*maxProxies,16); m_pHandlesRawPtr = btAlignedAlloc(sizeof(btSimpleBroadphaseProxy)*maxProxies,16);
m_pHandles = new(ptr) btSimpleBroadphaseProxy[maxProxies]; m_pHandles = new(m_pHandlesRawPtr) btSimpleBroadphaseProxy[maxProxies];
m_maxHandles = maxProxies; m_maxHandles = maxProxies;
m_numHandles = 0; m_numHandles = 0;
m_firstFreeHandle = 0; m_firstFreeHandle = 0;
@@ -73,7 +73,7 @@ btSimpleBroadphase::btSimpleBroadphase(int maxProxies, btOverlappingPairCache* o
btSimpleBroadphase::~btSimpleBroadphase() btSimpleBroadphase::~btSimpleBroadphase()
{ {
btAlignedFree(m_pHandles); btAlignedFree(m_pHandlesRawPtr);
if (m_ownsPairCache) if (m_ownsPairCache)
{ {

View File

@@ -59,6 +59,7 @@ protected:
int m_numHandles; // number of active handles int m_numHandles; // number of active handles
int m_maxHandles; // max number of handles int m_maxHandles; // max number of handles
btSimpleBroadphaseProxy* m_pHandles; // handles pool btSimpleBroadphaseProxy* m_pHandles; // handles pool
void* m_pHandlesRawPtr;
int m_firstFreeHandle; // free handles list int m_firstFreeHandle; // free handles list
int m_firstAllocatedHandle; int m_firstAllocatedHandle;