diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-04-18 00:06:06 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-04-18 00:06:06 +0400 |
commit | df8cf26404c7e922751643b1095e38f1ab430811 (patch) | |
tree | b4258cc6c90913c379f5cdd05edebd8785230647 /source/gameengine/Expressions/PyObjectPlus.h | |
parent | 90c6cf77f10961de756f6ff06329d3fa65ce3da4 (diff) |
Added m_zombie to the base python class (PyObjectPlus), when this is set all the subclasses will raise an error on access to their members.
Other small changes...
- KX_Camera and KX_Light didnt have get/setitem access in their PyType definition.
- CList.from_id() error checking for a long was checking for -1 against an unsigned value (own fault)
- CValue::SpecialRelease was incrementing an int for no reason.
- renamed m_attrlist to m_attr_dict since its a PyDict type.
- removed custom getattro/setattro functions for KX_Scene and KX_GameObject, use py_base_getattro, py_base_setattro for all subclasses of PyObjectPlus.
- lowercase windows.h in VideoBase.cpp for cross compiling.
Diffstat (limited to 'source/gameengine/Expressions/PyObjectPlus.h')
-rw-r--r-- | source/gameengine/Expressions/PyObjectPlus.h | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index ea26ea1d201..58a74e4ca74 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -400,10 +400,11 @@ class PyObjectPlus : public PyObject public: PyObjectPlus(PyTypeObject *T); + bool m_zombie; virtual ~PyObjectPlus(); // destructor static void PyDestructor(PyObject *P) // python wrapper - { + { delete ((PyObjectPlus *) P); }; @@ -417,6 +418,14 @@ public: virtual PyObject *py_getattro(PyObject *attr); // py_getattro method static PyObject *py_base_getattro(PyObject * self, PyObject *attr) // This should be the entry in Type. { + if (((PyObjectPlus*)self)->IsZombie()) { + if (!strcmp(PyString_AsString(attr), "isValid")) { + Py_RETURN_FALSE; + } + ((PyObjectPlus*)self)->IsZombiePyErr(); /* raise an error */ + return NULL; + } + return ((PyObjectPlus*) self)->py_getattro(attr); } @@ -432,10 +441,16 @@ public: virtual int py_setattro(PyObject *attr, PyObject *value); // py_setattro method static int py_base_setattro(PyObject *self, PyObject *attr, PyObject *value) // the PyType should reference this { + if (((PyObjectPlus*)self)->IsZombie()) { + /* you cant set isValid anyway */ + ((PyObjectPlus*)self)->IsZombiePyErr(); + return -1; + } + if (value==NULL) - return ((PyObjectPlus*) self)->py_delattro(attr); + return ((PyObjectPlus*)self)->py_delattro(attr); - return ((PyObjectPlus*) self)->py_setattro(attr, value); + return ((PyObjectPlus*)self)->py_setattro(attr, value); } virtual PyObject *py_repr(void); // py_repr method @@ -452,6 +467,41 @@ public: { return ((PyObjectPlus*)self)->Py_isA(value); } + + /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */ + static PyObject* pyattr_get_is_valid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + + bool IsZombie() + { + return m_zombie; + } + + bool IsZombiePyErr() + { + if(m_zombie) { + /* + PyObject *this_pystr = PyObject_Repr(this); + + PyErr_Format( + PyExc_RuntimeError, + "\"%s\" of type \"%s\" has been freed by the blender game engine, " + "scripts cannot access this anymore, check for this case with the \"isValid\" attribute", + PyString_AsString(this_pystr), ob_type->tp_name ); + + Py_DECREF(this_pystr); + */ + + PyErr_SetString(PyExc_RuntimeError, "This value has been freed by the blender game engine but python is still holding a reference, this value cant be used."); + } + + return m_zombie; + } + + void SetZombie(bool is_zombie) + { + m_zombie= is_zombie; + } + }; PyObject *py_getattr_dict(PyObject *pydict, PyObject *tp_dict); |