diff --git a/CHANGELOG.md b/CHANGELOG.md index 80551538..e9542e45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ do not hesitate to take a look at the user manual. - Issue with wrong linear velocity update computed in RigidBody::setLocalCenterOfMass() method - Issue with wrong linear velocity update computed in RigidBody::updateLocalCenterOfMassFromColliders() method - Issue with wrong linear velocity update computed in RigidBody::updateMassPropertiesFromColliders() method +- Issue in copy-constructors in Map and Set classes ## Version 0.8.0 (May 31, 2020) diff --git a/include/reactphysics3d/containers/Map.h b/include/reactphysics3d/containers/Map.h index 6bb4df00..a914659e 100755 --- a/include/reactphysics3d/containers/Map.h +++ b/include/reactphysics3d/containers/Map.h @@ -239,29 +239,32 @@ class Map { :mNbAllocatedEntries(map.mNbAllocatedEntries), mNbEntries(map.mNbEntries), mHashSize(map.mHashSize), mBuckets(nullptr), mEntries(nullptr), mNextEntries(nullptr), mAllocator(map.mAllocator), mFreeIndex(map.mFreeIndex) { - // Allocate memory for the buckets - mBuckets = static_cast(mAllocator.allocate(mHashSize * sizeof(uint32))); + if (mHashSize > 0) { - // Allocate memory for the entries - mEntries = static_cast*>(mAllocator.allocate(mNbAllocatedEntries * sizeof(Pair))); - mNextEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(uint32))); + // Allocate memory for the buckets + mBuckets = static_cast(mAllocator.allocate(mHashSize * sizeof(uint32))); - // Copy the buckets array - std::memcpy(mBuckets, map.mBuckets, mHashSize * sizeof(uint32)); + // Allocate memory for the entries + mEntries = static_cast*>(mAllocator.allocate(mNbAllocatedEntries * sizeof(Pair))); + mNextEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(uint32))); - // Copy the next entries indices - std::memcpy(mNextEntries, map.mNextEntries, mNbAllocatedEntries * sizeof(uint32)); + // Copy the buckets array + std::memcpy(mBuckets, map.mBuckets, mHashSize * sizeof(uint32)); - // Copy the entries - for (uint32 i=0; i(map.mEntries[entryIndex]); + uint32 entryIndex = mBuckets[i]; + while(entryIndex != INVALID_INDEX) { - entryIndex = mNextEntries[entryIndex]; + // Copy the entry to the new location and destroy the previous one + new (mEntries + entryIndex) Pair(map.mEntries[entryIndex]); + + entryIndex = mNextEntries[entryIndex]; + } } } } @@ -640,29 +643,32 @@ class Map { mHashSize = map.mHashSize; mFreeIndex = map.mFreeIndex; - // Allocate memory for the buckets - mBuckets = static_cast(mAllocator.allocate(mHashSize * sizeof(uint32))); + if (mHashSize > 0) { - // Allocate memory for the entries - mEntries = static_cast*>(mAllocator.allocate(mNbAllocatedEntries * sizeof(Pair))); - mNextEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(uint32))); + // Allocate memory for the buckets + mBuckets = static_cast(mAllocator.allocate(mHashSize * sizeof(uint32))); - // Copy the buckets array - std::memcpy(mBuckets, map.mBuckets, mHashSize * sizeof(uint32)); + // Allocate memory for the entries + mEntries = static_cast*>(mAllocator.allocate(mNbAllocatedEntries * sizeof(Pair))); + mNextEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(uint32))); - // Copy the next entries indices - std::memcpy(mNextEntries, map.mNextEntries, mNbAllocatedEntries * sizeof(uint32)); + // Copy the buckets array + std::memcpy(mBuckets, map.mBuckets, mHashSize * sizeof(uint32)); - // Copy the entries - for (uint32 i=0; i(map.mEntries[entryIndex]); + uint32 entryIndex = mBuckets[i]; + while(entryIndex != INVALID_INDEX) { - entryIndex = mNextEntries[entryIndex]; + // Copy the entry to the new location and destroy the previous one + new (mEntries + entryIndex) Pair(map.mEntries[entryIndex]); + + entryIndex = mNextEntries[entryIndex]; + } } } } diff --git a/include/reactphysics3d/containers/Set.h b/include/reactphysics3d/containers/Set.h index 3be397b8..f524d17a 100755 --- a/include/reactphysics3d/containers/Set.h +++ b/include/reactphysics3d/containers/Set.h @@ -239,29 +239,32 @@ class Set { :mNbAllocatedEntries(set.mNbAllocatedEntries), mNbEntries(set.mNbEntries), mHashSize(set.mHashSize), mBuckets(nullptr), mEntries(nullptr), mNextEntries(nullptr), mAllocator(set.mAllocator), mFreeIndex(set.mFreeIndex) { - // Allocate memory for the buckets - mBuckets = static_cast(mAllocator.allocate(mHashSize * sizeof(uint32))); + if (mHashSize > 0) { - // Allocate memory for the entries - mEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(V))); - mNextEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(uint32))); + // Allocate memory for the buckets + mBuckets = static_cast(mAllocator.allocate(mHashSize * sizeof(uint32))); - // Copy the buckets array - std::memcpy(mBuckets, set.mBuckets, mHashSize * sizeof(uint32)); + // Allocate memory for the entries + mEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(V))); + mNextEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(uint32))); - // Copy the next entries indices - std::memcpy(mNextEntries, set.mNextEntries, mNbAllocatedEntries * sizeof(uint32)); + // Copy the buckets array + std::memcpy(mBuckets, set.mBuckets, mHashSize * sizeof(uint32)); - // Copy the entries - for (uint32 i=0; i(mAllocator.allocate(mHashSize * sizeof(uint32))); + if (mHashSize > 0) { - // Allocate memory for the entries - mEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(V))); - mNextEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(uint32))); + // Allocate memory for the buckets + mBuckets = static_cast(mAllocator.allocate(mHashSize * sizeof(uint32))); - // Copy the buckets array - std::memcpy(mBuckets, set.mBuckets, mHashSize * sizeof(uint32)); + // Allocate memory for the entries + mEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(V))); + mNextEntries = static_cast(mAllocator.allocate(mNbAllocatedEntries * sizeof(uint32))); - // Copy the next entries indices - std::memcpy(mNextEntries, set.mNextEntries, mNbAllocatedEntries * sizeof(uint32)); + // Copy the buckets array + std::memcpy(mBuckets, set.mBuckets, mHashSize * sizeof(uint32)); - // Copy the entries - for (uint32 i=0; idestroyRigidBody(mRigidBody1); mWorld->destroyRigidBody(mRigidBody2Box); mWorld->destroyRigidBody(mRigidBody2Sphere); + + delete[] mConvexMeshPolygonFaces; + delete mConvexMeshPolygonVertexArray; } /// Run the tests