From 65d10d7b129cbba9b0b9365f19f34d3894ce9815 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Fri, 15 Jun 2007 23:49:52 +0000 Subject: [PATCH] Fixes in aligned object array, to call copy constructor, and not the assignment operator, operator= Also allows to use the array for classes with virtual methods. --- src/LinearMath/btAlignedObjectArray.h | 60 ++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/src/LinearMath/btAlignedObjectArray.h b/src/LinearMath/btAlignedObjectArray.h index 5d8112a88..8572da2c6 100644 --- a/src/LinearMath/btAlignedObjectArray.h +++ b/src/LinearMath/btAlignedObjectArray.h @@ -20,6 +20,16 @@ subject to the following restrictions: #include "btScalar.h" // has definitions like SIMD_FORCE_INLINE #include "btAlignedAllocator.h" +///If the platform doesn't support inplace new/memcpy, you can disable USE_NEW_INPLACE_NEW +///then the btAlignedObjectArray doesn't support objects with virtual methods, and non-trivial constructors/destructors +///see discussion here: http://continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1231 +#define USE_NEW_INPLACE_NEW 1 +#ifdef USE_NEW_INPLACE_NEW +#include //in-place new +#include //memcpy +#endif //USE_NEW_INPLACE_NEW + + ///btAlignedObjectArray uses a subset of the stl::vector interface for its methods ///It is developed to replace stl::vector to avoid STL alignment issues to add SIMD/SSE data template @@ -41,7 +51,11 @@ class btAlignedObjectArray { int i; for (i=start;i size()) + int curSize = size(); + + if (newsize < size()) { - reserve(newsize); + for(int i = curSize; i < newsize; i++) + { + m_data[i].~T(); + } + } else + { + if (newsize > size()) + { + reserve(newsize); + } +#ifdef USE_NEW_INPLACE_NEW + for (int i=curSize;i