diff options
author | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-12-29 04:34:07 +0300 |
---|---|---|
committer | Kester Maddock <Christopher.Maddock.1@uni.massey.ac.nz> | 2004-12-29 04:34:07 +0300 |
commit | 8e5ef105aed627fc81c4fd0cb8f2fd045b471cfa (patch) | |
tree | 027f0b4a9cff417bb1b3f5ae27379a1506df4618 /source/gameengine/Ketsji/KX_PyMath.h | |
parent | c82614be2eb04dcca48d705e013ffa86058bceaf (diff) |
Make Python Matrix/Vector conversions more robust
Diffstat (limited to 'source/gameengine/Ketsji/KX_PyMath.h')
-rw-r--r-- | source/gameengine/Ketsji/KX_PyMath.h | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index 322a9d32a7d..a588334f621 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -61,17 +61,25 @@ bool PyMatTo(PyObject* pymat, T& mat) if (PySequence_Check(pymat)) { unsigned int rows = PySequence_Size(pymat); - for (unsigned int y = 0; y < rows && y < Size(mat); y++) + if (rows != Size(mat)) + return false; + + for (unsigned int y = 0; noerror && y < Size(mat); y++) { PyObject *pyrow = PySequence_GetItem(pymat, y); /* new ref */ - if (PySequence_Check(pyrow)) + if (!PyErr_Occurred() && PySequence_Check(pyrow)) { unsigned int cols = PySequence_Size(pyrow); - for( unsigned int x = 0; x < cols && x < Size(mat); x++) + if (cols != Size(mat)) + noerror = false; + else { - PyObject *item = PySequence_GetItem(pyrow, x); /* new ref */ - mat[y][x] = PyFloat_AsDouble(item); - Py_DECREF(item); + for( unsigned int x = 0; x < Size(mat); x++) + { + PyObject *item = PySequence_GetItem(pyrow, x); /* new ref */ + mat[y][x] = PyFloat_AsDouble(item); + Py_DECREF(item); + } } } else noerror = false; @@ -92,7 +100,10 @@ bool PyVecTo(PyObject* pyval, T& vec) if (PySequence_Check(pyval)) { unsigned int numitems = PySequence_Size(pyval); - for (unsigned int x = 0; x < numitems && x < Size(vec); x++) + if (numitems != Size(vec)) + return false; + + for (unsigned int x = 0; x < numitems; x++) { PyObject *item = PySequence_GetItem(pyval, x); /* new ref */ vec[x] = PyFloat_AsDouble(item); |