From 551f0fa1ec689a776569194bf2949f4b11b14929 Mon Sep 17 00:00:00 2001 From: "john.mccutchan" Date: Thu, 7 Aug 2008 16:02:59 +0000 Subject: [PATCH] Keep track of raw pointer returned from btAlignedAlloc when using placement new on an array. --- .../BroadphaseCollision/btAxisSweep3.h | 15 +++++++++------ .../BroadphaseCollision/btSimpleBroadphase.cpp | 6 +++--- .../BroadphaseCollision/btSimpleBroadphase.h | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h b/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h index e3b194259..72ae4da3b 100644 --- a/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h +++ b/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h @@ -77,9 +77,11 @@ protected: BP_FP_INT_TYPE m_numHandles; // number of active handles BP_FP_INT_TYPE m_maxHandles; // max number of handles Handle* m_pHandles; // handles pool + void* m_pHandlesRawPtr; 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) + void* m_pEdgesRawPtr[3]; btOverlappingPairCache* m_pairCache; @@ -269,8 +271,9 @@ m_invalidPair(0) m_quantize = btVector3(btScalar(maxInt),btScalar(maxInt),btScalar(maxInt)) / aabbSize; // allocate handles buffer and put all handles on free list - void* ptr = btAlignedAlloc(sizeof(Handle)*maxHandles,16); - m_pHandles = new(ptr) Handle[maxHandles]; + m_pHandlesRawPtr = btAlignedAlloc(sizeof(Handle)*maxHandles,16); + m_pHandles = new(m_pHandlesRawPtr) Handle[maxHandles]; + m_maxHandles = maxHandles; m_numHandles = 0; @@ -286,8 +289,8 @@ m_invalidPair(0) // allocate edge buffers for (int i = 0; i < 3; i++) { - void* ptr = btAlignedAlloc(sizeof(Edge)*maxHandles*2,16); - m_pEdges[i] = new(ptr) Edge[maxHandles * 2]; + m_pEdgesRawPtr[i] = btAlignedAlloc(sizeof(Edge)*maxHandles*2,16); + m_pEdges[i] = new(m_pEdgesRawPtr[i]) Edge[maxHandles * 2]; } } //removed overlap management @@ -319,9 +322,9 @@ btAxisSweep3Internal::~btAxisSweep3Internal() for (int i = 2; i >= 0; i--) { - btAlignedFree(m_pEdges[i]); + btAlignedFree(m_pEdgesRawPtr[i]); } - btAlignedFree(m_pHandles); + btAlignedFree(m_pHandlesRawPtr); if (m_ownsPairCache) { diff --git a/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp b/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp index acab8d1e9..2d27f2256 100644 --- a/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp +++ b/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp @@ -50,8 +50,8 @@ btSimpleBroadphase::btSimpleBroadphase(int maxProxies, btOverlappingPairCache* o } // allocate handles buffer and put all handles on free list - void* ptr = btAlignedAlloc(sizeof(btSimpleBroadphaseProxy)*maxProxies,16); - m_pHandles = new(ptr) btSimpleBroadphaseProxy[maxProxies]; + m_pHandlesRawPtr = btAlignedAlloc(sizeof(btSimpleBroadphaseProxy)*maxProxies,16); + m_pHandles = new(m_pHandlesRawPtr) btSimpleBroadphaseProxy[maxProxies]; m_maxHandles = maxProxies; m_numHandles = 0; m_firstFreeHandle = 0; @@ -73,7 +73,7 @@ btSimpleBroadphase::btSimpleBroadphase(int maxProxies, btOverlappingPairCache* o btSimpleBroadphase::~btSimpleBroadphase() { - btAlignedFree(m_pHandles); + btAlignedFree(m_pHandlesRawPtr); if (m_ownsPairCache) { diff --git a/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h b/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h index 76bb93036..6013c6a16 100644 --- a/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h +++ b/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h @@ -59,6 +59,7 @@ protected: int m_numHandles; // number of active handles int m_maxHandles; // max number of handles btSimpleBroadphaseProxy* m_pHandles; // handles pool + void* m_pHandlesRawPtr; int m_firstFreeHandle; // free handles list int m_firstAllocatedHandle;