Index: trunk/src/world_entities/skybox.cc
===================================================================
--- trunk/src/world_entities/skybox.cc	(revision 5750)
+++ trunk/src/world_entities/skybox.cc	(revision 5994)
@@ -92,10 +92,9 @@
 {
   PRINTF(5)("Deleting SkyBox\n");
+  this->setModel(NULL); //< so that WorldEntity does not try to delete it again.
   for (int i = 0; i < 6; i++)
     delete this->material[i];
   delete[] this->material;
-  delete this->model;
-  this->model = NULL; //< so that WorldEntity does not try to delete it again.
-}
+ }
 
 /**
@@ -171,42 +170,42 @@
 void SkyBox::rebuild()
 {
-  if (this->model)
-    delete this->model;
-  model = new Model();
-
-  this->model->addVertex (-0.5*size, -0.5*size, 0.5*size);
-  this->model->addVertex (0.5*size, -0.5*size, 0.5*size);
-  this->model->addVertex (-0.5*size, 0.5*size, 0.5*size);
-  this->model->addVertex (0.5*size, 0.5*size, 0.5*size);
-  this->model->addVertex (-0.5*size, 0.5*size, -0.5*size);
-  this->model->addVertex (0.5*size, 0.5*size, -0.5*size);
-  this->model->addVertex (-0.5*size, -0.5*size, -0.5*size);
-  this->model->addVertex (0.5*size, -0.5*size, -0.5*size);
-
-  this->model->addVertexTexture (0.0, 1.0);
-  this->model->addVertexTexture (1.0, 1.0);
-  this->model->addVertexTexture (1.0, 0.0);
-  this->model->addVertexTexture (0.0, 0.0);
-
-  this->model->addVertexNormal (0.0, 0.0, 1.0);
-  this->model->addVertexNormal (0.0, 1.0, 0.0);
-  this->model->addVertexNormal (0.0, 0.0, -1.0);
-  this->model->addVertexNormal (0.0, -1.0, 0.0);
-  this->model->addVertexNormal (1.0, 0.0, 0.0);
-  this->model->addVertexNormal (-1.0, 0.0, 0.0);
-
-  this->model->setMaterial(material[0]);
-  this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,0,3, 3,1,3, 5,2,3, 4,3,3); // top
-  this->model->setMaterial(material[1]);
-  this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,1, 7,1,1, 1,2,1, 0,3,1); // bottom
-  this->model->setMaterial(material[2]);
-  this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,2,2, 5,3,2, 7,0,2, 6,1,2); // left
-  this->model->setMaterial(material[3]);
-  this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,0, 3,2,0, 2,3,0); // right
-  this->model->setMaterial(material[4]);
-  this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,0,5, 7,1,5, 5,2,5, 3,3,5); // front
-  this->model->setMaterial(material[5]);
-  this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,4, 0,1,4, 2,2,4, 4,3,4); // back
-
-  this->model->finalize();
-}
+  Model* model = new Model();
+
+  model->addVertex (-0.5*size, -0.5*size, 0.5*size);
+  model->addVertex (0.5*size, -0.5*size, 0.5*size);
+  model->addVertex (-0.5*size, 0.5*size, 0.5*size);
+  model->addVertex (0.5*size, 0.5*size, 0.5*size);
+  model->addVertex (-0.5*size, 0.5*size, -0.5*size);
+  model->addVertex (0.5*size, 0.5*size, -0.5*size);
+  model->addVertex (-0.5*size, -0.5*size, -0.5*size);
+  model->addVertex (0.5*size, -0.5*size, -0.5*size);
+
+  model->addVertexTexture (0.0, 1.0);
+  model->addVertexTexture (1.0, 1.0);
+  model->addVertexTexture (1.0, 0.0);
+  model->addVertexTexture (0.0, 0.0);
+
+  model->addVertexNormal (0.0, 0.0, 1.0);
+  model->addVertexNormal (0.0, 1.0, 0.0);
+  model->addVertexNormal (0.0, 0.0, -1.0);
+  model->addVertexNormal (0.0, -1.0, 0.0);
+  model->addVertexNormal (1.0, 0.0, 0.0);
+  model->addVertexNormal (-1.0, 0.0, 0.0);
+
+  model->setMaterial(material[0]);
+  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,0,3, 3,1,3, 5,2,3, 4,3,3); // top
+  model->setMaterial(material[1]);
+  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,1, 7,1,1, 1,2,1, 0,3,1); // bottom
+  model->setMaterial(material[2]);
+  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,2,2, 5,3,2, 7,0,2, 6,1,2); // left
+  model->setMaterial(material[3]);
+  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,0, 3,2,0, 2,3,0); // right
+  model->setMaterial(material[4]);
+  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,0,5, 7,1,5, 5,2,5, 3,3,5); // front
+  model->setMaterial(material[5]);
+  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,4, 0,1,4, 2,2,4, 4,3,4); // back
+
+  model->finalize();
+
+  this->setModel(model);
+}
