Anonymous avatar Anonymous committed c516ff0

Fixed reference counts. Fixed value assignment for joint.distance

Comments (0)

Files changed (2)

src/pgBodyObject.c

         if (tmp)
         {
             double mass = PyFloat_AsDouble (tmp);
+            Py_DECREF (tmp);
             if (PyErr_Occurred ())
                 return -1;
             if (mass < 0)
         if (tmp)
         {
             double rotation = PyFloat_AsDouble (tmp);
+            Py_DECREF (tmp);
             if (PyErr_Occurred ())
                 return -1;
             body->fRotation = rotation;
         if (tmp)
         {
             double torque = PyFloat_AsDouble (tmp);
+            Py_DECREF (tmp);
             if (PyErr_Occurred ())
                 return -1;
             body->fTorque = torque;
         if (tmp)
         {
             double rest = PyFloat_AsDouble (tmp);
+            Py_DECREF (tmp);
             if (PyErr_Occurred ())
                 return -1;
             body->fRestitution = rest;
             return 0;
         }
     }
-    PyErr_SetString (PyExc_TypeError, "torque must be a float");
+    PyErr_SetString (PyExc_TypeError, "restitution must be a float");
     return -1;
 }
 
         if (tmp)
         {
             double friction = PyFloat_AsDouble (tmp);
+            Py_DECREF (tmp);
             if (PyErr_Occurred ())
                 return -1;
             body->fFriction = friction;
             return 0;
         }
     }
-    PyErr_SetString (PyExc_TypeError, "torque must be a float");
+    PyErr_SetString (PyExc_TypeError, "friction must be a float");
     return -1;
 }
 
 */
 static int _pgBody_setBStatic (pgBodyObject* body,PyObject* value,void* closure)
 {
-	if (PyInt_Check (value))
+	if (PyBool_Check (value))
 	{
-		body->bStatic = PyInt_AsLong (value);
-		return 0;
+            body->bStatic = (value == Py_True) ? 1 : 0;
+            return 0;
 
 	}
-	PyErr_SetString (PyExc_TypeError, "torque must be a float");
+	PyErr_SetString (PyExc_TypeError, "static must be a bool");
 	return -1;
 }
 
     {"velocity",(getter)_pgBody_getVelocity,(setter)_pgBody_setVelocity,"velocity",NULL},
     {"position",(getter)_pgBody_getPosition,(setter)_pgBody_setPosition,"position",NULL},
     {"force",(getter)_pgBody_getForce,(setter)_pgBody_setForce,"force",NULL},
-	{"static",(getter)_pgBody_getBStatic,(setter)_pgBody_setBStatic,"whether static",NULL},
+    {"static",(getter)_pgBody_getBStatic,(setter)_pgBody_setBStatic,"whether static",NULL},
     { NULL, NULL, NULL, NULL, NULL}
 };
 

src/pgJointObject.c

 	//printf("dvBody %f,%f\n",dvBody.real,dvBody.imag);
 	if (c_get_length(body->vecLinearVelocity) < 100)
 	{
-		printf("joint\n");
-		printf("body speed:%f,%f\n",body->vecLinearVelocity.real,body->vecLinearVelocity.imag);
+/* 		printf("joint\n"); */
+/* 		printf("body speed:%f,%f\n",body->vecLinearVelocity.real,body->vecLinearVelocity.imag); */
 	}
 
 	//for position correction
 
 static int _pgDistanceJoint_setDistance(pgDistanceJointObject* joint,PyObject* value,void* closure)
 {
-	if(PyFloat_Check(value))
-	{
-		joint->distance = PyFloat_AsDouble(value);
-		return 0;
-	}
-	else
-	{
-		PyErr_SetString(PyExc_TypeError, "value must be float number");
-		return -1;
-	}
+    if (PyNumber_Check (value))
+    {
+        PyObject *tmp = PyNumber_Float (value);
+
+        if (tmp)
+        {
+            double distance = PyFloat_AsDouble (tmp);
+            Py_DECREF (tmp);
+            if (PyErr_Occurred ())
+                return -1;
+            joint->distance = distance;
+            return 0;
+        }
+    }
+    PyErr_SetString (PyExc_TypeError, "distance must be a float");
+    return -1;
 }
 
 static PyObject* _pgDistanceJoint_getAnchor1(pgDistanceJointObject* joint,void* closure)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.