From 357826aa6e18c3af1625223656d748b92db86696 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Dec 2010 08:29:41 +0000 Subject: bugfix [#24967] bge.KX_GameObject.worldAngularVelocity does not work, breaks mathutils somehow - Exceptions from reading vector values in the game engine where not being caught. - Also wrote specific KX_GameObject exceptions, without these the errors are quite confusing. --- source/gameengine/Ketsji/KX_GameObject.cpp | 16 ++++++++++------ source/gameengine/Ketsji/KX_PyMath.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'source/gameengine/Ketsji') diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 6b1c36a1589..1de7eee134e 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1266,7 +1266,9 @@ static int mathutils_kxgameob_vector_get(BaseMathObject *bmo, int subtype) KX_GameObject* self= static_castBGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; - + +#define PHYS_ERR(attr) PyErr_SetString(PyExc_AttributeError, "KX_GameObject." attr ", is missing a physics controller") + switch(subtype) { case MATHUTILS_VEC_CB_POS_LOCAL: self->NodeGetLocalPosition().getValue(bmo->data); @@ -1281,31 +1283,33 @@ static int mathutils_kxgameob_vector_get(BaseMathObject *bmo, int subtype) self->NodeGetWorldScaling().getValue(bmo->data); break; case MATHUTILS_VEC_CB_INERTIA_LOCAL: - if(!self->GetPhysicsController()) return 0; + if(!self->GetPhysicsController()) return PHYS_ERR("localInertia"), 0; self->GetPhysicsController()->GetLocalInertia().getValue(bmo->data); break; case MATHUTILS_VEC_CB_OBJECT_COLOR: self->GetObjectColor().getValue(bmo->data); break; case MATHUTILS_VEC_CB_LINVEL_LOCAL: - if(!self->GetPhysicsController()) return 0; + if(!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), 0; self->GetLinearVelocity(true).getValue(bmo->data); break; case MATHUTILS_VEC_CB_LINVEL_GLOBAL: - if(!self->GetPhysicsController()) return 0; + if(!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), 0; self->GetLinearVelocity(false).getValue(bmo->data); break; case MATHUTILS_VEC_CB_ANGVEL_LOCAL: - if(!self->GetPhysicsController()) return 0; + if(!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), 0; self->GetAngularVelocity(true).getValue(bmo->data); break; case MATHUTILS_VEC_CB_ANGVEL_GLOBAL: - if(!self->GetPhysicsController()) return 0; + if(!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), 0; self->GetAngularVelocity(false).getValue(bmo->data); break; } +#undef PHYS_ERR + return 1; } diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index 589bd72c760..282e9a8f1f6 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -110,7 +110,9 @@ bool PyVecTo(PyObject* pyval, T& vec) if(VectorObject_Check(pyval)) { VectorObject *pyvec= (VectorObject *)pyval; - BaseMath_ReadCallback(pyvec); + if(!BaseMath_ReadCallback(pyvec)) { + return false; /* exception raised */ + } if (pyvec->size != Size(vec)) { PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", pyvec->size, Size(vec)); return false; @@ -120,7 +122,9 @@ bool PyVecTo(PyObject* pyval, T& vec) } else if(QuaternionObject_Check(pyval)) { QuaternionObject *pyquat= (QuaternionObject *)pyval; - BaseMath_ReadCallback(pyquat); + if(!BaseMath_ReadCallback(pyquat)) { + return false; /* exception raised */ + } if (4 != Size(vec)) { PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", 4, Size(vec)); return false; @@ -131,7 +135,9 @@ bool PyVecTo(PyObject* pyval, T& vec) } else if(EulerObject_Check(pyval)) { EulerObject *pyeul= (EulerObject *)pyval; - BaseMath_ReadCallback(pyeul); + if(!BaseMath_ReadCallback(pyeul)) { + return false; /* exception raised */ + } if (3 != Size(vec)) { PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", 3, Size(vec)); return false; -- cgit v1.2.3