Repository: bulletphysics/bullet3

Issue:
Only physics client 0 taken into account for pybullet_setCollisionFilterPair and pybullet_setCollisionFilterGroupMask
Hi,

I have several simulation instances in DIRECT mode, with a robot in each. When I load the robot into the simulation, I apply some collision filters in order to avoid specific links to self collide. I noticed those filters are correctly applied on the physics client 0, but not on the others...

The problem seems to be coming from the method pybullet_setCollisionFilterPair (the pybullet_setCollisionFilterGroupMask method has the same problem) in examples/pybullet/pybullet.c,
```c 
sm = getPhysicsClient(physicsClientId);
```
Is called before parsing the arguments, physicsClientId is by default set to 0, so the filter is always applied to the client 0.

Thanks for that wonderful simulator !


Discussion:

Patch:
diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c
index b506fa183c..260e7ad5a6 100644
--- a/examples/pybullet/pybullet.c
+++ b/examples/pybullet/pybullet.c
@@ -6293,17 +6293,17 @@ static PyObject* pybullet_setCollisionFilterGroupMask(PyObject* self, PyObject*
 
 	static char* kwlist[] = {"bodyUniqueId", "linkIndexA", "collisionFilterGroup", "collisionFilterMask", "physicsClientId", NULL};
 
+	if (!PyArg_ParseTupleAndKeywords(args, keywds, "iiii|i", kwlist,
+									 &bodyUniqueIdA, &linkIndexA, &collisionFilterGroup, &collisionFilterMask, &physicsClientId))
+		return NULL;
+
 	sm = getPhysicsClient(physicsClientId);
 	if (sm == 0)
 	{
 		PyErr_SetString(SpamError, "Not connected to physics server.");
 		return NULL;
 	}
-
-	if (!PyArg_ParseTupleAndKeywords(args, keywds, "iiii|i", kwlist,
-									 &bodyUniqueIdA, &linkIndexA, &collisionFilterGroup, &collisionFilterMask, &physicsClientId))
-		return NULL;
-
+	
 	commandHandle = b3CollisionFilterCommandInit(sm);
 	b3SetCollisionFilterGroupMask(commandHandle, bodyUniqueIdA, linkIndexA, collisionFilterGroup, collisionFilterMask);
 
@@ -6329,6 +6329,10 @@ static PyObject* pybullet_setCollisionFilterPair(PyObject* self, PyObject* args,
 
 	static char* kwlist[] = {"bodyUniqueIdA", "bodyUniqueIdB", "linkIndexA", "linkIndexB", "enableCollision", "physicsClientId", NULL};
 
+	if (!PyArg_ParseTupleAndKeywords(args, keywds, "iiiii|i", kwlist,
+									 &bodyUniqueIdA, &bodyUniqueIdB, &linkIndexA, &linkIndexB, &enableCollision, &physicsClientId))
+		return NULL;
+
 	sm = getPhysicsClient(physicsClientId);
 	if (sm == 0)
 	{
@@ -6336,10 +6340,6 @@ static PyObject* pybullet_setCollisionFilterPair(PyObject* self, PyObject* args,
 		return NULL;
 	}
 
-	if (!PyArg_ParseTupleAndKeywords(args, keywds, "iiiii|i", kwlist,
-									 &bodyUniqueIdA, &bodyUniqueIdB, &linkIndexA, &linkIndexB, &enableCollision, &physicsClientId))
-		return NULL;
-
 	commandHandle = b3CollisionFilterCommandInit(sm);
 	b3SetCollisionFilterPair(commandHandle, bodyUniqueIdA, bodyUniqueIdB, linkIndexA, linkIndexB, enableCollision);