From 9185f93174d5e24f06dbec6bb4c2868fd72617ed Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Mon, 25 Apr 2022 18:31:07 -0700 Subject: [PATCH 1/3] manually copy data, to avoid possible memory leaks. --- src/Bullet3Common/b3AlignedObjectArray.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Bullet3Common/b3AlignedObjectArray.h b/src/Bullet3Common/b3AlignedObjectArray.h index 7d31b56d0..8ef3331f7 100644 --- a/src/Bullet3Common/b3AlignedObjectArray.h +++ b/src/Bullet3Common/b3AlignedObjectArray.h @@ -135,7 +135,11 @@ public: int otherSize = otherArray.size(); resize(otherSize); - otherArray.copy(0, otherSize, m_data); + //don't use otherArray.copy, it can leak memory + for (int i = 0; i < otherSize; i++) + { + m_data[i] = otherArray[i]; + } } /// return the number of elements in the array @@ -506,7 +510,11 @@ public: { int otherSize = otherArray.size(); resize(otherSize); - otherArray.copy(0, otherSize, m_data); + //don't use otherArray.copy, it can leak memory + for (int i = 0; i < otherSize; i++) + { + m_data[i] = otherArray[i]; + } } void removeAtIndex(int index) From ae4c1f8e72964790ec1214baf3e8b0a031a5c08b Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Mon, 25 Apr 2022 18:33:59 -0700 Subject: [PATCH 2/3] bump up pybullet to 3.24 --- VERSION | 2 +- setup.py | 2 +- src/LinearMath/btScalar.h | 2 +- src/LinearMath/btSerializer.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 0f4de9d99..bd2342316 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.23 +3.24 diff --git a/setup.py b/setup.py index 21a6c2d2f..86a7a9cbe 100644 --- a/setup.py +++ b/setup.py @@ -505,7 +505,7 @@ if 'BT_USE_EGL' in EGL_CXX_FLAGS: setup( name='pybullet', - version='3.2.3', + version='3.2.4', description= 'Official Python Interface for the Bullet Physics SDK specialized for Robotics Simulation and Reinforcement Learning', long_description= diff --git a/src/LinearMath/btScalar.h b/src/LinearMath/btScalar.h index e27b71594..9f5408c79 100644 --- a/src/LinearMath/btScalar.h +++ b/src/LinearMath/btScalar.h @@ -25,7 +25,7 @@ subject to the following restrictions: #include /* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/ -#define BT_BULLET_VERSION 323 +#define BT_BULLET_VERSION 324 inline int btGetVersion() { diff --git a/src/LinearMath/btSerializer.h b/src/LinearMath/btSerializer.h index 9c5525fb9..59695ab32 100644 --- a/src/LinearMath/btSerializer.h +++ b/src/LinearMath/btSerializer.h @@ -481,7 +481,7 @@ public: buffer[9] = '3'; buffer[10] = '2'; - buffer[11] = '3'; + buffer[11] = '4'; } virtual void startSerialization() From a899725cc699354765dda47398e039e7bd58bfb4 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Mon, 25 Apr 2022 19:32:25 -0700 Subject: [PATCH 3/3] clear the m_userVisualShapeHandles at resetSimulation to avoid memory build-up (not a leak at exit, since memory was del-allocated in the destructor) --- .../SharedMemory/PhysicsServerCommandProcessor.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index d3f1ee799..8275451ed 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -240,6 +240,10 @@ struct InternalVisualShapeData b3AlignedObjectArray m_pathPrefixes; + virtual ~InternalVisualShapeData() + { + clear(); + } void clear() { m_tinyRendererVisualShapeIndex = -1; @@ -259,8 +263,14 @@ struct InternalCollisionShapeData m_used(0) { } + + virtual ~InternalCollisionShapeData() + { + clear(); + } void clear() { + m_urdfCollisionObjects.clear(); m_collisionShape = 0; m_used = 0; } @@ -15949,6 +15959,9 @@ void PhysicsServerCommandProcessor::resetSimulation(int flags) m_data->m_bodyHandles.exitHandles(); m_data->m_bodyHandles.initHandles(); + m_data->m_userVisualShapeHandles.exitHandles(); + m_data->m_userVisualShapeHandles.initHandles(); + m_data->m_userCollisionShapeHandles.exitHandles(); m_data->m_userCollisionShapeHandles.initHandles();