Index: orxonox/trunk/src/lib/collision_detection/lin_alg.h
===================================================================
--- orxonox/trunk/src/lib/collision_detection/lin_alg.h	(revision 4629)
+++ orxonox/trunk/src/lib/collision_detection/lin_alg.h	(revision 4630)
@@ -49,5 +49,8 @@
       for (iq=ip+1; iq<=N; iq++)
         sm=sm+fabs(A[ip][iq]);
-    if (sm==0) {
+    if (sm==0)
+    {
+      free(B);
+      free(Z);
       return;       //normal return
     }
Index: orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc
===================================================================
--- orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc	(revision 4629)
+++ orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc	(revision 4630)
@@ -45,4 +45,9 @@
 OBBTree*  OBBTreeNode::obbTree = NULL;
 
+float**  OBBTreeNode::coMat = NULL;
+float**  OBBTreeNode::eigvMat = NULL;
+float*   OBBTreeNode::eigvlMat = NULL;
+int*     OBBTreeNode::rotCount = NULL;
+
 /**
    \brief standard constructor
@@ -53,4 +58,23 @@
   this->nodeLeft = NULL;
   this->nodeRight = NULL;
+
+  if(coMat == NULL)
+  {
+    coMat = new float*[4];
+    for(int i = 0; i < 4; i++)
+      coMat[i] = new float[4];
+  }
+  if(eigvMat == NULL)
+  {
+    eigvMat = new float*[4];
+    for(int i = 0; i < 4; i++)
+      eigvMat[i] = new float[4];
+  }
+  if( eigvlMat == NULL)
+  {
+    eigvlMat = new float[4];
+  }
+  if( rotCount == NULL)
+    rotCount = new int;
 }
 
@@ -76,5 +100,5 @@
   this->depth = depth;
 
-  this->bvElement = this->createBox();
+  this->bvElement = new OBB();
   PRINTF(0)("Created OBBox\n");
   this->calculateBoxAttributes(this->bvElement, verticesList, length);
@@ -85,12 +109,16 @@
     this->forkBox(this->bvElement);
 
-  }
-}
-
-
-OBB* OBBTreeNode::createBox()
-{
-  return new OBB();
-}
+    OBBTreeNode*       node1 = new OBBTreeNode();
+    OBBTreeNode*       node2 = new OBBTreeNode();
+
+    this->nodeLeft = node1;
+    this->nodeRight = node2;
+
+    this->nodeLeft->spawnBVTree(depth - 1, this->tmpVert1, this->tmpLen1);
+    this->nodeRight->spawnBVTree(depth - 1, this->tmpVert2, this->tmpLen2);
+
+  }
+}
+
 
 
@@ -188,34 +216,20 @@
   vectors
   */
- /* Matrix                V(3,3);    */                           //!< for eigenvectors
- /* DiagonalMatrix        D(3);   */                              //!< for eigenvalues
-/*  SymmetricMatrix       C(3); */                                //!< for the covariance symmetrical matrix
   Vector**              axis = new Vector*[3];                //!< the references to the obb axis
-
+//   float**               a = new float*[4];
+//   float**               b = new float*[4];
+//   float                 eigval[3];
+//   int*                  rot = new int;
+
+
+  //coMat[0] = new float[4]; coMat[1] = new float[4]; coMat[2] = new float[4]; coMat[3] = new float[4];
+  //eigvMat[0] = new float[4]; eigvMat[1] = new float[4]; eigvMat[2] = new float[4]; eigvMat[3] = new float[4];
+
+  coMat[1][1] = covariance[0][0]; coMat[1][2] = covariance[0][1]; coMat[1][3] = covariance[0][2];
+  coMat[2][1] = covariance[1][0]; coMat[2][2] = covariance[1][1]; coMat[2][3] = covariance[1][2];
+  coMat[3][1] = covariance[2][0]; coMat[3][2] = covariance[2][1]; coMat[3][3] = covariance[2][2];
 
   /* new jacobi tests */
-  float** a = new float*[4];
-  a[0] = new float[4]; a[1] = new float[4]; a[2] = new float[4]; a[3] = new float[4];
-
-  float** b = new float*[4];
-  b[0] = new float[4]; b[1] = new float[4]; b[2] = new float[4]; b[3] = new float[4];
-
-  float eigval[3];
-
-  int* rot = new int;
-
-
-  a[1][1] = covariance[0][0];
-  a[1][2] = covariance[0][1];
-  a[1][3] = covariance[0][2];
-  a[2][1] = covariance[1][0];
-  a[2][2] = covariance[1][1];
-  a[2][3] = covariance[1][2];
-  a[3][1] = covariance[2][0];
-  a[3][2] = covariance[2][1];
-  a[3][3] = covariance[2][2];
-
-
-  JacobI(a, 3, eigval, b, rot);
+  JacobI(coMat, 3, eigvlMat, eigvMat, rotCount);
   PRINTF(0)("-- Done Jacobi Decomposition\n");
 
@@ -228,31 +242,27 @@
 //     for(int k = 1; k < 4; ++k)
 //     {
-//       printf(" \b%f ", b[j][k]);
+//       printf(" \b%f ", eigvMat[j][k]);
 //     }
 //     printf(" |\n");
 //   }
 
-  axis[0] = new Vector(b[1][1], b[2][1], b[3][1]);
-  axis[1] = new Vector(b[1][2], b[2][2], b[3][2]);
-  axis[2] = new Vector(b[1][3], b[2][3], b[3][3]);
+  axis[0] = new Vector(eigvMat[1][1], eigvMat[2][1], eigvMat[3][1]);
+  axis[1] = new Vector(eigvMat[1][2], eigvMat[2][2], eigvMat[3][2]);
+  axis[2] = new Vector(eigvMat[1][3], eigvMat[2][3], eigvMat[3][3]);
   box->axis = axis;
   PRINTF(0)("-- Got Axis\n");
-
-  delete [] a[0];
-  delete [] a[1];
-  delete [] a[2];
-  delete [] a[3];
-  delete [] a;
-
-  delete [] b[0];
-  delete [] b[1];
-  delete [] b[2];
-  delete [] b[3];
-  delete [] b;
-
 
 //   printf("\neigenvector: %f, %f, %f\n", box->axis[0]->x, box->axis[0]->y, box->axis[0]->z);
 //   printf("eigenvector: %f, %f, %f\n", box->axis[1]->x, box->axis[1]->y, box->axis[1]->z);
 //   printf("eigenvector: %f, %f, %f\n", box->axis[2]->x, box->axis[2]->y, box->axis[2]->z);
+
+
+//   delete [] a[0]; delete [] a[1]; delete [] a[2]; delete [] a[3];
+//   delete [] a;
+//
+//   delete [] b[0]; delete [] b[1]; delete [] b[2]; delete [] b[3];
+//   delete [] b;
+//
+//   delete rot;
 
 
@@ -291,5 +301,5 @@
   box->halfLength = halfLength;
   PRINTF(0)("-- Written Axis to obb\n");
-
+  PRINTF(0)("-- Finished Calculating Attributes\n");
 
 //   printf("\nwe got length: \n");
@@ -403,4 +413,9 @@
     element = iterator->nextElement();
   }
+
+  this->tmpVert1 = vertList1;
+  this->tmpVert2 = vertList2;
+  this->tmpLen1 = partition1.getSize();
+  this->tmpLen2 = partition2.getSize();
 
   //delete iterator;
@@ -412,14 +427,4 @@
 //     printf("v[%i][2] = %f\n", i, vertList2[i][2]);
 //   }
-
-  /* now spawn the obb tree: create the nodes and descent */
-  OBBTreeNode*       node1 = new OBBTreeNode();
-  OBBTreeNode*       node2 = new OBBTreeNode();
-
-  this->nodeLeft = node1;
-  this->nodeRight = node2;
-
-  this->nodeLeft->spawnBVTree(depth - 1, vertList1, partition1.getSize());
-  this->nodeRight->spawnBVTree(depth - 1, vertList2, partition2.getSize());
 }
 
Index: orxonox/trunk/src/lib/collision_detection/obb_tree_node.h
===================================================================
--- orxonox/trunk/src/lib/collision_detection/obb_tree_node.h	(revision 4629)
+++ orxonox/trunk/src/lib/collision_detection/obb_tree_node.h	(revision 4630)
@@ -41,5 +41,4 @@
 
   private:
-    OBB* createBox();
     void calculateBoxAttributes(OBB* box, sVec3D* verticesList, int length);
     void forkBox(OBB* box);
@@ -58,4 +57,15 @@
     int                 depth;                      //!< the depth of the node in the tree
     static OBBTree*     obbTree;                    //!< reference to the obb tree
+
+    /* tmp saving place for obb variables */
+    sVec3D*             tmpVert1;
+    sVec3D*             tmpVert2;
+    int                 tmpLen1;
+    int                 tmpLen2;
+
+    static float**       coMat;
+    static float**       eigvMat;
+    static float*        eigvlMat;
+    static int*          rotCount;
 };
 
