From 6ca649a0e1f49d1dfd803a7c82a5ec72e887286a Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Thu, 12 Apr 2018 12:26:21 -0700 Subject: [PATCH 1/2] PyBullet: fix a memory leak in setJointMotorControlArray Fixes Issue #1633 --- examples/pybullet/pybullet.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 2c86daef8..31cdc20eb 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -1909,6 +1909,7 @@ static PyObject* pybullet_setJointMotorControlArray(PyObject* self, PyObject* ar { Py_DECREF(kpsSeq); } + PyErr_SetString(SpamError, "number of kds should match the number of joint indices"); return NULL; } @@ -1993,6 +1994,29 @@ static PyObject* pybullet_setJointMotorControlArray(PyObject* self, PyObject* ar statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle); + + if (targetVelocitiesSeq) + { + Py_DECREF(targetVelocitiesSeq); + } + if (targetPositionsSeq) + { + Py_DECREF(targetPositionsSeq); + } + if (forcesSeq) + { + Py_DECREF(forcesSeq); + } + if (kpsSeq) + { + Py_DECREF(kpsSeq); + } + + if (kdsSeq) + { + Py_DECREF(kdsSeq); + } + Py_DECREF(jointIndicesSeq); Py_INCREF(Py_None); return Py_None; From c7d9afac1ec3aee4be74f9f3c894ef0b65eb808c Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Tue, 1 May 2018 09:23:08 -0700 Subject: [PATCH 2/2] fix SoftDemo crash, due to changes in OpenGLGuiHelper rendering fixes Issue #1655 --- examples/ExampleBrowser/OpenGLGuiHelper.cpp | 19 +++++++++++++++---- examples/SoftDemo/SoftDemo.cpp | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.cpp b/examples/ExampleBrowser/OpenGLGuiHelper.cpp index b21aae329..536843450 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.cpp +++ b/examples/ExampleBrowser/OpenGLGuiHelper.cpp @@ -433,10 +433,14 @@ void OpenGLGuiHelper::createCollisionShapeGraphicsObject(btCollisionShape* colli if (collisionShape->getShapeType() == SOFTBODY_SHAPE_PROXYTYPE) { computeSoftBodyVertices(collisionShape, gfxVertices, indices); - int shapeId = registerGraphicsShape(&gfxVertices[0].xyzw[0], gfxVertices.size(), &indices[0], indices.size(), B3_GL_TRIANGLES, - m_data->m_checkedTexture); - b3Assert(shapeId >= 0); - collisionShape->setUserIndex(shapeId); + if (gfxVertices.size() && indices.size()) + { + int shapeId = registerGraphicsShape(&gfxVertices[0].xyzw[0], gfxVertices.size(), &indices[0], indices.size(), B3_GL_TRIANGLES, + m_data->m_checkedTexture); + + b3Assert(shapeId >= 0); + collisionShape->setUserIndex(shapeId); + } } if (collisionShape->getShapeType()==MULTI_SPHERE_SHAPE_PROXYTYPE) { @@ -1265,6 +1269,11 @@ void OpenGLGuiHelper::autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWor btCollisionObject* colObj = sortedObjects[i]; //btRigidBody* body = btRigidBody::upcast(colObj); //does this also work for btMultiBody/btMultiBodyLinkCollider? + btSoftBody* sb = btSoftBody::upcast(colObj); + if (sb) + { + colObj->getCollisionShape()->setUserPointer(sb); + } createCollisionShapeGraphicsObject(colObj->getCollisionShape()); int colorIndex = colObj->getBroadphaseHandle()->getUid() & 3; @@ -1313,6 +1322,8 @@ void OpenGLGuiHelper::computeSoftBodyVertices(btCollisionShape* collisionShape, btAlignedObjectArray& gfxVertices, btAlignedObjectArray& indices) { + if (collisionShape->getUserPointer()==0) + return; b3Assert(collisionShape->getUserPointer()); btSoftBody* psb = (btSoftBody*)collisionShape->getUserPointer(); gfxVertices.resize(psb->m_faces.size() * 3); diff --git a/examples/SoftDemo/SoftDemo.cpp b/examples/SoftDemo/SoftDemo.cpp index c1e58dfd7..9b09adafe 100644 --- a/examples/SoftDemo/SoftDemo.cpp +++ b/examples/SoftDemo/SoftDemo.cpp @@ -169,7 +169,7 @@ public: for ( int i=0;igetSoftBodyArray().size();i++) { btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i]; - if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe))) + //if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe))) { btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer()); btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags());