Revision: 27754
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27754
Author:   ben2610
Date:     2010-03-25 22:43:36 +0100 (Thu, 25 Mar 2010)

Log Message:
-----------
BGE: [#19836] Recursive Parenting in game crashes Blender. Added parenting loop 
detection.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/SceneGraph/SG_Node.cpp
    trunk/blender/source/gameengine/SceneGraph/SG_Node.h

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2010-03-25 
21:40:08 UTC (rev 27753)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp    2010-03-25 
21:43:36 UTC (rev 27754)
@@ -234,7 +234,11 @@
 void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj, bool 
addToCompound, bool ghost)
 {
        // check on valid node in case a python controller holds a reference to 
a deleted object
-       if (obj && GetSGNode() && obj->GetSGNode() && 
GetSGNode()->GetSGParent() != obj->GetSGNode())
+       if (obj && 
+               GetSGNode() &&                  // object is not zombi
+               obj->GetSGNode() &&             // object is not zombi
+               GetSGNode()->GetSGParent() != obj->GetSGNode() &&       // not 
already parented to same object
+               !GetSGNode()->IsAncessor(obj->GetSGNode()))                     
// no parenting loop
        {
                // Make sure the objects have some scale
                MT_Vector3 scale1 = NodeGetWorldScaling();

Modified: trunk/blender/source/gameengine/SceneGraph/SG_Node.cpp
===================================================================
--- trunk/blender/source/gameengine/SceneGraph/SG_Node.cpp      2010-03-25 
21:40:08 UTC (rev 27753)
+++ trunk/blender/source/gameengine/SceneGraph/SG_Node.cpp      2010-03-25 
21:43:36 UTC (rev 27754)
@@ -150,6 +150,12 @@
        return (m_SGparent ? (const SG_Node*) m_SGparent->GetRootSGParent() : 
(const SG_Node*) this);
 }
 
+bool SG_Node::IsAncessor(const SG_Node* child) const
+{
+       return (!child->m_SGparent) ? false : 
+               (child->m_SGparent == this) ? true : 
IsAncessor(child->m_SGparent);
+}
+
        void 
 SG_Node::
 DisconnectFromParent(

Modified: trunk/blender/source/gameengine/SceneGraph/SG_Node.h
===================================================================
--- trunk/blender/source/gameengine/SceneGraph/SG_Node.h        2010-03-25 
21:40:08 UTC (rev 27753)
+++ trunk/blender/source/gameengine/SceneGraph/SG_Node.h        2010-03-25 
21:43:36 UTC (rev 27754)
@@ -77,6 +77,13 @@
                SG_Node* child
        );
 
+       /**
+        * Return true if the node is the ancessor of child
+        */
+               bool
+       IsAncessor(
+               const SG_Node* child
+       ) const;
        /** 
         * Get the current list of children. Do not use this interface for
         * adding or removing children please use the methods of this class for


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to