From e8f4d9322112e64677df11ba834a26159874b332 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 15 Apr 2009 10:57:28 +0000 Subject: 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. --- source/gameengine/PyDoc/KX_GameObject.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/gameengine/PyDoc') diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 44b84d44d8d..4aa9de2fe86 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -12,6 +12,7 @@ class KX_GameObject: # (SCA_IObject) All game objects are derived from this class. Properties assigned to game objects are accessible as attributes of this class. + - note: Calling ANY method or attribute on an object that has been removed from a scene will raise a RuntimeError, if an object may have been removed since last accessing it use the L{isValid} attribute to check. @ivar name: The object's name. (Read only) - note: Currently (Blender 2.49) the prefix "OB" is added to all objects name. This may change in blender 2.5. @@ -63,6 +64,8 @@ class KX_GameObject: # (SCA_IObject) - note: This attribute is experemental and may be removed (but probably wont be). - note: Changes to this list will not update the KX_GameObject. @type actuators: list + @ivar isValid: Retuerns fails when the object has been removed from the scene and can no longer be used. + @type isValid: bool """ def endObject(visible): """ -- cgit v1.2.3