Index: /trunk/src/lib/coord/p_node.cc
===================================================================
--- /trunk/src/lib/coord/p_node.cc	(revision 6074)
+++ /trunk/src/lib/coord/p_node.cc	(revision 6075)
@@ -91,5 +91,5 @@
           ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT))
       {
-        if (this == PNode::getNullParent() && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULLPARENT)
+        if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULLPARENT)
           delete (*deleteNode);
         else
@@ -111,4 +111,7 @@
   if (this->toDirection != NULL)
     delete this->toDirection;
+
+  if (this == PNode::nullParent)
+    PNode::nullParent = NULL;
 }
 
@@ -459,12 +462,18 @@
 {
   if( likely(child->parent != NULL))
-    {
-      PRINTF(5)("PNode::addChild() - reparenting node: removing it and adding it again\n");
       child->parent->children.remove(child);
-    }
-  child->parent = this;
-  if (unlikely(this != NULL))
-    this->children.push_back(child);
-  child->parentCoorChanged();
+  if (this->checkIntegrity(child))
+  {
+    child->parent = this;
+    if (unlikely(this != NULL))
+      this->children.push_back(child);
+    child->parentCoorChanged();
+  }
+  else
+  {
+    PRINTF(1)("Tried to reparent to own child '%s::%s' to '%s::%s'.\n",
+              this->getClassName(), this->getName(), child->getClassName(), child->getName());
+    child->parent = NULL;
+  }
 }
 
@@ -492,4 +501,17 @@
   if (child != NULL)
    child->removeNode();
+}
+
+
+/**
+ * !! PRIVATE FUNCTION
+ * @brief reparents a node (happens on Parents Node delete or remove if Flags are set.)
+ */
+void PNode::reparent()
+{
+  if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT)
+    this->setParent(PNode::getNullParent());
+  else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL)
+    this->setParent(this->parent->getParent());
 }
 
@@ -508,5 +530,6 @@
     while (child != this->children.end())
     {
-      reparenter = child++;
+      reparenter = child;
+      child++;
       (*reparenter)->reparent();
     }
@@ -526,4 +549,7 @@
   if (parentNode != NULL)
     parentNode->addChild(this);
+  else
+    PRINTF(2)("Not Found PNode's (%s::%s) new Parent by Name: %s\n",
+              this->getClassName(), this->getName(), parentName);
 }
 
@@ -537,6 +563,8 @@
 {
   // return if the new parent and the old one match
-  if (this->parent == parentNode)
+  if (this->parent == parentNode )
     return;
+  if (parentNode == NULL)
+    parentNode = PNode::getNullParent();
 
   // store the Valures to iterate to.
@@ -597,17 +625,9 @@
 }
 
-
-/**
- * !!PRIVATE FUNCTION:
- * @brief reparents a node (happens on Parents Node delete or remove if Flags are set.)
- */
-void PNode::reparent()
-{
-  if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT)
-    this->setParent(PNode::getNullParent());
-  else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL)
-    this->setParent(this->parent->getParent());
-}
-
+/**
+ * @brief adds special mode Flags to this PNode
+ * @see PARENT_MODE
+ * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator.
+ */
 void PNode::addNodeModeFlags(unsigned short nodeFlags)
 {
@@ -615,8 +635,31 @@
 }
 
-
+/**
+ * @brief removes special mode Flags to this PNode
+ * @see PARENT_MODE
+ * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator.
+ */
 void PNode::removeNodeModeFlags(unsigned short nodeFlags)
 {
   this->parentMode &= !nodeFlags;
+}
+
+
+/**
+ * !! PRIVATE FUNCTION
+ * @brief checks the upward integrity (e.g if PNode is somewhere up the Node tree.)
+ * @param checkParent the Parent to check.
+ * @returns true if the integrity-check succeeds, false otherwise.
+ *
+ * If there is a second occurence of checkParent before NULL, then a loop could get
+ * into the Tree, and we do not want this.
+ */
+bool PNode::checkIntegrity(const PNode* checkParent) const
+{
+  const PNode* parent = this;
+  while ( (parent = parent->getParent()) != NULL)
+    if (unlikely(parent == checkParent))
+      return false;
+  return true;
 }
 
@@ -632,8 +675,8 @@
 void PNode::updateNode (float dt)
 {
-  if( likely(this->parent != NULL))
+  if (!(this->parentMode & PNODE_STATIC_NODE))
+  {
+    if( likely(this->parent != NULL))
     {
-      if (!(this->parentMode & PNODE_STATIC_NODE))
-      {
         // movement for nodes with smoothMove enabled
         if (unlikely(this->toCoordinate != NULL))
@@ -663,5 +706,5 @@
             delete this->toDirection;
             this->toDirection = NULL;
-             PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
+            PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
           }
         }
@@ -670,5 +713,6 @@
         this->lastAbsCoordinate = this->absCoordinate;
 
-        PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
+        PRINTF(5)("PNode::update - '%s::%s' - (%f, %f, %f)\n", this->getClassName(), this->getName(),
+                      this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
 
 
@@ -682,22 +726,21 @@
         if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
         {
-         /* update the current absCoordinate */
-         this->prevRelCoordinate = this->relCoordinate;
-         this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
+        /* update the current absCoordinate */
+        this->prevRelCoordinate = this->relCoordinate;
+        this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
         }
         else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
         {
           /* update the current absCoordinate */
-         this->prevRelCoordinate = this->relCoordinate;
-         this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
+        this->prevRelCoordinate = this->relCoordinate;
+        this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
         }
         /////////////////////////////////////////////////
       }
-  }
-   else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT
+
+  else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT
     {
-      if (!(this->parentMode & PNODE_STATIC_NODE))
-      {
-        PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
+      PRINTF(4)("update ParentLess Node (%s::%s) - (%f, %f, %f)\n", this->getClassName(), this->getName(),
+                this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
         if (this->bRelCoorChanged)
         {
@@ -733,4 +776,10 @@
 
 
+
+
+
+/*************
+ * DEBUGGING *
+ *************/
 /**
  * @brief counts total amount the children walking through the entire tree.
Index: /trunk/src/lib/coord/p_node.h
===================================================================
--- /trunk/src/lib/coord/p_node.h	(revision 6074)
+++ /trunk/src/lib/coord/p_node.h	(revision 6075)
@@ -179,4 +179,5 @@
 
   void reparent();
+  bool checkIntegrity(const PNode* checkParent) const;
 
  private:
