bugfix for: [#26753] PhysicsConstraints ID trouble on 64bit (linux at least).
authorDalai Felinto <dfelinto@gmail.com>
Sat, 28 May 2011 08:16:34 +0000 (08:16 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Sat, 28 May 2011 08:16:34 +0000 (08:16 +0000)
[the problem also affected OSX]

PhysicsId are Long, not ints (see PyObject* KX_GameObject::PyGetPhysicsId() )

There is a reference in the code to use PyCapsule instead of int. I'm not sure
about that. This patch at least stops the crashes
(update: I talked with Campbell and he repeated that PyCapsule are better, but if long is working it's fine for now).

source/gameengine/Ketsji/KX_PyConstraintBinding.cpp

index bf288e1f1add0dff456df6313573cc1ed59650de..1202465714933e43b0d1ff747c22947c6d0b3471 100644 (file)
@@ -405,8 +405,13 @@ static PyObject* gPyCreateConstraint(PyObject* self,
                                                                                 PyObject* args, 
                                                                                 PyObject* kwds)
 {
-       /* FIXME - physicsid is an int being cast to a pointer, should at least use PyCapsule */
-       int physicsid=0,physicsid2 = 0,constrainttype=0,extrainfo=0;
+       /* FIXME - physicsid is a long being cast to a pointer, should at least use PyCapsule */
+#if defined(_WIN64)
+       __int64 physicsid=0,physicsid2 = 0;
+#else
+       long physicsid=0,physicsid2 = 0;
+#endif
+       int constrainttype=0, extrainfo=0;
        int len = PyTuple_Size(args);
        int success = 1;
        int flag = 0;
@@ -414,27 +419,51 @@ static PyObject* gPyCreateConstraint(PyObject* self,
        float pivotX=1,pivotY=1,pivotZ=1,axisX=0,axisY=0,axisZ=1;
        if (len == 3)
        {
-               success = PyArg_ParseTuple(args,"iii",&physicsid,&physicsid2,&constrainttype);
+#if defined(_WIN64)
+               success = PyArg_ParseTuple(args,"LLi",&physicsid,&physicsid2,&constrainttype);
+#else
+               success = PyArg_ParseTuple(args,"lli",&physicsid,&physicsid2,&constrainttype);
+#endif
        }
        else
        if (len ==6)
        {
-               success = PyArg_ParseTuple(args,"iiifff",&physicsid,&physicsid2,&constrainttype,
+#if defined(_WIN64)
+               success = PyArg_ParseTuple(args,"LLifff",&physicsid,&physicsid2,&constrainttype,
                        &pivotX,&pivotY,&pivotZ);
+#else
+               success = PyArg_ParseTuple(args,"llifff",&physicsid,&physicsid2,&constrainttype,
+                                                                  &pivotX,&pivotY,&pivotZ);            
+#endif 
        }
        else if (len == 9)
        {
-               success = PyArg_ParseTuple(args,"iiiffffff",&physicsid,&physicsid2,&constrainttype,
+#if defined(_WIN64)
+               success = PyArg_ParseTuple(args,"LLiffffff",&physicsid,&physicsid2,&constrainttype,
                        &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ);
+#else
+               success = PyArg_ParseTuple(args,"lliffffff",&physicsid,&physicsid2,&constrainttype,
+                                                                  &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ);
+#endif
+       
        }
        else if (len == 10)
        {
-               success = PyArg_ParseTuple(args,"iiiffffffi",&physicsid,&physicsid2,&constrainttype,
+#if defined(_WIN64)
+               success = PyArg_ParseTuple(args,"LLiffffffi",&physicsid,&physicsid2,&constrainttype,
                        &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag);
+#else
+               success = PyArg_ParseTuple(args,"lliffffffi",&physicsid,&physicsid2,&constrainttype,
+                                                                  &pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag);
+#endif
        }
        else if (len==4)
        {
-               success = PyArg_ParseTuple(args,"iiii",&physicsid,&physicsid2,&constrainttype,&extrainfo);
+#if defined(_WIN64)
+               success = PyArg_ParseTuple(args,"LLii",&physicsid,&physicsid2,&constrainttype,&extrainfo);
+#else
+               success = PyArg_ParseTuple(args,"llii",&physicsid,&physicsid2,&constrainttype,&extrainfo);
+#endif
                pivotX=extrainfo;
        }