Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-15 14:57:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-15 14:57:28 +0400
commite8f4d9322112e64677df11ba834a26159874b332 (patch)
treea26e20a97d0c6b79c06da995b6b64c01a0fb057c /source/gameengine/Ketsji/KX_Camera.cpp
parent19c869ab64a0e14727217c7d221e03d32a614132 (diff)
Disable using KX_GameObjects in python that have been removed from the scene (zombie objects) by raising a RuntimeError when accessing methods, attributes or passing to a function.
Common cases of this are when python references an object from the AddObject actuator that has ended, or a scene has been loaded and the old objects freed. This means some scripts will raise errors now in certain cases but better give the error early rather then failing silently with strange hard to track down behavior & crashes. Added "isValid" attribute for checking objects are in a scene. At the moment it uses the SceneGraph Node to check of the objects valid but it might be better to do this in a more generic way so scenes, meshes etc also have this check.
Diffstat (limited to 'source/gameengine/Ketsji/KX_Camera.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_Camera.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp
index 8032e939a50..befc8462aa3 100644
--- a/source/gameengine/Ketsji/KX_Camera.cpp
+++ b/source/gameengine/Ketsji/KX_Camera.cpp
@@ -534,11 +534,22 @@ PyParentObject KX_Camera::Parents[] = {
PyObject* KX_Camera::py_getattro(PyObject *attr)
{
+ if (ValidPythonToGameObject(this)==false) {
+ if (!strcmp(PyString_AsString(attr), "isValid")) {
+ PyErr_Clear();
+ Py_RETURN_FALSE;
+ }
+ return NULL; /* ValidPythonToGameObject sets the error */
+ }
+
py_getattro_up(KX_GameObject);
}
int KX_Camera::py_setattro(PyObject *attr, PyObject *value)
{
+ if (ValidPythonToGameObject(this)==false)
+ return -1;
+
py_setattro_up(KX_GameObject);
}