From 4e0aa42123895a11dadb21760decf9ed9a4cf18d Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Tue, 15 Nov 2011 20:09:05 +0000 Subject: [PATCH] Disallow the operator= for btAlignedObjectArray, together with some fixes in the code (to avoid accidental deep copy) Enable #define BT_ALLOW_ARRAY_COPY_OPERATOR in Bullet/LinearMath/btAlignedObjectArray.h to re-enable it Fixes Issue 564, thanks to Tissen Peter for the report/fix --- Extras/ConvexDecomposition/ConvexBuilder.cpp | 2 +- .../CollisionShapes/btOptimizedBvh.cpp | 4 ++-- src/LinearMath/btAlignedObjectArray.h | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Extras/ConvexDecomposition/ConvexBuilder.cpp b/Extras/ConvexDecomposition/ConvexBuilder.cpp index b3d6a8c6c..bf576af6f 100644 --- a/Extras/ConvexDecomposition/ConvexBuilder.cpp +++ b/Extras/ConvexDecomposition/ConvexBuilder.cpp @@ -251,7 +251,7 @@ bool ConvexBuilder::combineHulls(void) if ( combine ) { mChulls.clear(); - mChulls = output; + mChulls.copyFromArray(output); output.clear(); } diff --git a/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp b/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp index 981b8a265..6f36775f7 100644 --- a/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp +++ b/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp @@ -43,7 +43,7 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized NodeTriangleCallback& operator=(NodeTriangleCallback& other) { - m_triangleNodes = other.m_triangleNodes; + m_triangleNodes.copyFromArray(other.m_triangleNodes); return *this; } @@ -84,7 +84,7 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized QuantizedNodeTriangleCallback& operator=(QuantizedNodeTriangleCallback& other) { - m_triangleNodes = other.m_triangleNodes; + m_triangleNodes.copyFromArray(other.m_triangleNodes); m_optimizedTree = other.m_optimizedTree; return *this; } diff --git a/src/LinearMath/btAlignedObjectArray.h b/src/LinearMath/btAlignedObjectArray.h index 9022a941e..d70f10862 100644 --- a/src/LinearMath/btAlignedObjectArray.h +++ b/src/LinearMath/btAlignedObjectArray.h @@ -28,6 +28,7 @@ subject to the following restrictions: #define BT_USE_PLACEMENT_NEW 1 //#define BT_USE_MEMCPY 1 //disable, because it is cumbersome to find out for each platform where memcpy is defined. It can be in or or otherwise... +//#define BT_ALLOW_ARRAY_COPY_OPERATOR // enabling this can accidently perform deep copies of data if you are not careful #ifdef BT_USE_MEMCPY #include @@ -53,7 +54,19 @@ class btAlignedObjectArray //PCK: added this line bool m_ownsMemory; - protected: +#ifdef BT_ALLOW_ARRAY_COPY_OPERATOR +public: + SIMD_FORCE_INLINE btAlignedObjectArray& operator=(btAlignedObjectArray &other) + { + copyFromArray(other); + return *this; + } +#else//BT_ALLOW_ARRAY_COPY_OPERATOR +private: + SIMD_FORCE_INLINE btAlignedObjectArray& operator=(btAlignedObjectArray &other); +#endif//BT_ALLOW_ARRAY_COPY_OPERATOR + +protected: SIMD_FORCE_INLINE int allocSize(int size) { return (size ? size*2 : 1);