PyBullet: fix memory leak in case connection to shared memory cannot be made

PyBullet: allow setJointMotorControl2 to use maxVelocity in combination with obsolete 'bodyIndex'
This commit is contained in:
erwincoumans
2018-01-15 08:33:19 -08:00
parent 3c770e56fb
commit 387d3f16db

View File

@@ -440,7 +440,9 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P
} }
} }
if (sm && b3CanSubmitCommand(sm)) if (sm)
{
if (b3CanSubmitCommand(sm))
{ {
for (i = 0; i < MAX_PHYSICS_CLIENTS; i++) for (i = 0; i < MAX_PHYSICS_CLIENTS; i++)
{ {
@@ -476,6 +478,10 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P
return PyInt_FromLong(-1); return PyInt_FromLong(-1);
} }
} }
} else
{
b3DisconnectSharedMemory(sm);
}
} }
return PyInt_FromLong(freeIndex); return PyInt_FromLong(freeIndex);
} }
@@ -1995,10 +2001,10 @@ static PyObject* pybullet_setJointMotorControl2(PyObject* self, PyObject* args,
&targetPosition, &targetVelocity, &force, &kp, &kd, &maxVelocity, &physicsClientId)) &targetPosition, &targetVelocity, &force, &kp, &kd, &maxVelocity, &physicsClientId))
{ {
//backward compatibility, bodyIndex -> bodyUniqueId, don't need to update this function: people have to migrate to bodyUniqueId //backward compatibility, bodyIndex -> bodyUniqueId, don't need to update this function: people have to migrate to bodyUniqueId
static char* kwlist2[] = {"bodyIndex", "jointIndex", "controlMode", "targetPosition", "targetVelocity", "force", "positionGain", "velocityGain", "physicsClientId", NULL}; static char* kwlist2[] = {"bodyIndex", "jointIndex", "controlMode", "targetPosition", "targetVelocity", "force", "positionGain", "velocityGain", "maxVelocity","physicsClientId", NULL};
PyErr_Clear(); PyErr_Clear();
if (!PyArg_ParseTupleAndKeywords(args, keywds, "iii|dddddi", kwlist2, &bodyUniqueId, &jointIndex, &controlMode, if (!PyArg_ParseTupleAndKeywords(args, keywds, "iii|ddddddi", kwlist2, &bodyUniqueId, &jointIndex, &controlMode,
&targetPosition, &targetVelocity, &force, &kp, &kd, &physicsClientId)) &targetPosition, &targetVelocity, &force, &kp, &kd, &maxVelocity, &physicsClientId))
{ {
return NULL; return NULL;
} }