Index: trunk/src/glmenu/glmenu_imagescreen.cc
===================================================================
--- trunk/src/glmenu/glmenu_imagescreen.cc	(revision 5307)
+++ trunk/src/glmenu/glmenu_imagescreen.cc	(revision 5308)
@@ -284,4 +284,2 @@
   SDL_GL_SwapBuffers();
 }
-
-
Index: trunk/src/lib/graphics/importer/material.cc
===================================================================
--- trunk/src/lib/graphics/importer/material.cc	(revision 5307)
+++ trunk/src/lib/graphics/importer/material.cc	(revision 5308)
@@ -57,8 +57,10 @@
 Material::~Material()
 {
-  PRINTF(4)("delete Material %s.\n", this->getName());
+  PRINTF(5)("delete Material %s.\n", this->getName());
 
   if (this->diffuseTexture != NULL)
+  {
     ResourceManager::getInstance()->unload(this->diffuseTexture);
+  }
   if (this->ambientTexture != NULL)
     ResourceManager::getInstance()->unload(this->ambientTexture);
@@ -69,6 +71,6 @@
 /**
  *  sets the material with which the following Faces will be painted
-*/
-bool Material::select ()
+ */
+bool Material::select () const
 {
   // setting diffuse color
@@ -127,5 +129,5 @@
  *  Sets the Material Illumination Model.
  *  illu illumination Model in int form
-*/
+ */
 void Material::setIllum (int illum)
 {
@@ -133,8 +135,10 @@
   this->illumModel = illum;
 }
+
 /**
  *  Sets the Material Illumination Model.
  *  illu illumination Model in char* form
-*/void Material::setIllum (char* illum)
+ */
+void Material::setIllum (char* illum)
 {
   this->setIllum (atoi(illum));
@@ -146,5 +150,5 @@
  * @param g Green Color Channel.
  * @param b Blue Color Channel.
-*/
+ */
 void Material::setDiffuse (float r, float g, float b)
 {
@@ -156,8 +160,9 @@
 
 }
+
 /**
  *  Sets the Material Diffuse Color.
  * @param rgb The red, green, blue channel in char format (with spaces between them)
-*/
+ */
 void Material::setDiffuse (char* rgb)
 {
@@ -181,8 +186,9 @@
   this->ambient[3] = 1.0;
 }
+
 /**
  *  Sets the Material Ambient Color.
  * @param rgb The red, green, blue channel in char format (with spaces between them)
-*/
+ */
 void Material::setAmbient (char* rgb)
 {
@@ -197,5 +203,5 @@
  * @param g Green Color Channel.
  * @param b Blue Color Channel.
-*/
+ */
 void Material::setSpecular (float r, float g, float b)
 {
@@ -206,4 +212,5 @@
   this->specular[3] = 1.0;
  }
+
 /**
  *  Sets the Material Specular Color.
@@ -269,5 +276,5 @@
 void Material::setDiffuseMap(const char* dMap)
 {
-  PRINTF(4)("setting Diffuse Map %s\n", dMap);
+  PRINTF(5)("setting Diffuse Map %s\n", dMap);
   if (this->diffuseTexture != NULL)
     ResourceManager::getInstance()->unload(this->diffuseTexture);
Index: trunk/src/lib/graphics/importer/material.h
===================================================================
--- trunk/src/lib/graphics/importer/material.h	(revision 5307)
+++ trunk/src/lib/graphics/importer/material.h	(revision 5308)
@@ -26,7 +26,7 @@
  public:
   Material (const char* mtlName = NULL);
-  ~Material ();
+  virtual ~Material ();
 
-  bool select ();
+  bool select () const;
 
   void setIllum (int illum);
@@ -58,5 +58,5 @@
   float       shininess;        //!< The shininess of the Material.
   float       transparency;     //!< The transperency of the Material.
-
+  public:
   Texture*    diffuseTexture;   //!< The diffuse texture of the Material.
   Texture*    ambientTexture;   //!< The ambient texture of the Material.
Index: trunk/src/lib/graphics/importer/model.cc
===================================================================
--- trunk/src/lib/graphics/importer/model.cc	(revision 5307)
+++ trunk/src/lib/graphics/importer/model.cc	(revision 5308)
@@ -65,5 +65,4 @@
 
   this->next = NULL;
-
 }
 
@@ -383,5 +382,5 @@
 //////////
 /**
- *  adds a new Material to the Material List
+ * adds a new Material to the Material List
  * @param material the Material to add
  * @returns the added material
@@ -392,4 +391,6 @@
 Material* Model::addMaterial(Material* material)
 {
+  if (material == NULL)
+    return NULL;
   ModelMaterial* modMat = new ModelMaterial;
   modMat->external = true;
@@ -408,6 +409,5 @@
   ModelMaterial* modMat = new ModelMaterial;
   modMat->external = false;
-  modMat->material = new Material();
-  modMat->material->setName(materialName);
+  modMat->material = new Material(materialName);
 
   // adding material to the List of materials
@@ -474,5 +474,4 @@
   float subbuffer3;
   sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
-  PRINTF(5)("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3);
   this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor);
   this->vertexCount++;
@@ -507,5 +506,4 @@
   float subbuffer3;
   sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
-  PRINTF(5)("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3);
   this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
   this->normalCount++;
@@ -543,5 +541,4 @@
   float subbuffer2;
   sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2);
-  PRINTF(5)("found vertex-Texture %f, %f\n", &subbuffer1, &subbuffer2);
   this->vTexture->addEntry(subbuffer1);
   this->vTexture->addEntry(1 - subbuffer2);
@@ -659,5 +656,5 @@
 
 /**
- *  Function that selects a material, if changed in the obj file.
+ * Function that selects a material, if changed in the obj file.
  * @param matString the Material that will be set.
 */
@@ -674,5 +671,5 @@
 
 /**
- *  Function that selects a material, if changed in the obj file.
+ * Function that selects a material, if changed in the obj file.
  * @param mtl the Material that will be set.
 */
@@ -1106,4 +1103,3 @@
   this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,16, 7,10,17, 5,11,18, 3,3,19);
   this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,12,20, 0,0,21, 2,2,22, 4,13,23);
-
-}
+}
Index: trunk/src/lib/graphics/importer/texture.h
===================================================================
--- trunk/src/lib/graphics/importer/texture.h	(revision 5307)
+++ trunk/src/lib/graphics/importer/texture.h	(revision 5308)
@@ -21,5 +21,5 @@
 
 //! A Class, that reads in Textures from different fileformats.
-class Texture : public  BaseObject
+class Texture : public BaseObject
 {
  public:
Index: trunk/src/util/resource_manager.cc
===================================================================
--- trunk/src/util/resource_manager.cc	(revision 5307)
+++ trunk/src/util/resource_manager.cc	(revision 5308)
@@ -251,5 +251,4 @@
     {
       PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
-//      printf("adding %s count: %d\n", tmpResource->pointer->getName(),  tmpResource->count);
       tmpResource->count++;
       if(tmpResource->prio < prio)
@@ -409,5 +408,5 @@
     }
   else
-    unload(tmpResource, prio);
+    return unload(tmpResource, prio);
 }
 
@@ -416,4 +415,5 @@
  * @param resource: The resource to unloade
  * @param prio the PriorityLevel to unload this resource
+ * @returns true on success, false otherwise.
 */
 bool ResourceManager::unload(Resource* resource, ResourcePriority prio)
@@ -421,5 +421,4 @@
   if (resource == NULL)
     return false;
-//  printf("removing %s count: %d\n", resource->pointer->getName(),  resource->count);
   if (resource->count > 0)
     resource->count--;
@@ -427,5 +426,5 @@
   if (resource->prio <= prio)
     {
-      if (resource->count <= 0)
+      if (resource->count == 0)
         {
           // deleting the Resource
@@ -480,5 +479,5 @@
 
 /**
- *  unloads all alocated Memory of Resources with a pririty lower than prio
+ * unloads all alocated Memory of Resources with a pririty lower than prio
  * @param prio The priority to delete
 */
@@ -486,5 +485,5 @@
 {
   tIterator<Resource>* iterator = resourceList->getIterator();
-  Resource* enumRes = iterator->firstElement();
+  Resource* enumRes = iterator->lastElement();
   while (enumRes)
     {
@@ -496,5 +495,5 @@
                    enumRes->name, enumRes->count);
       //enumRes = resourceList->nextElement();
-      enumRes = iterator->nextElement();
+      enumRes = iterator->prevElement();
     }
   delete iterator;
Index: trunk/src/util/resource_manager.h
===================================================================
--- trunk/src/util/resource_manager.h	(revision 5307)
+++ trunk/src/util/resource_manager.h	(revision 5308)
@@ -66,5 +66,5 @@
 {
   BaseObject*       pointer;           //!< Pointer to the Resource.
-  int               count;             //!< How many times this Resource has been loaded.
+  unsigned int      count;             //!< How many times this Resource has been loaded.
 
   char*             name;              //!< Name of the Resource.
@@ -85,11 +85,12 @@
 //! The ResourceManager is a class, that decides if a file/resource should be loaded
 /**
-   If a file/resource was already loaded the resourceManager will
-   return a void pointer to the desired resource.
-   Otherwise it will instruct the corresponding resource-loader to load,
-   and receive the pointer to it.
-
-   It does it by looking, if a desired file has already been loaded.
-*/
+ * If a file/resource was already loaded the resourceManager will
+ * return a pointer to the desired resource.
+ * Otherwise it will instruct the corresponding resource-loader to load,
+ * and receive the pointer to it.
+ *
+ * It does it by looking, if a desired file has already been loaded.
+ * There is also the possibility to check for some variables
+ */
 class ResourceManager : public BaseObject
 {
@@ -101,5 +102,5 @@
   bool setDataDir(const char* dataDir);
   /** @returns the Name of the data directory */
-  inline const char* getDataDir() const {return this->dataDir;}
+  inline const char* getDataDir() const { return this->dataDir; };
 
   bool checkDataDir(const char* fileInside);
@@ -135,6 +136,6 @@
   static ResourceManager*  singletonRef;       //!< singleton Reference
 
+  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
   tList<Resource>*         resourceList;       //!< The List of Resources, that has already been loaded.
-  char*                    dataDir;            //!< The Data Directory, where all relevant Data is stored.
   tList<char>*             imageDirs;          //!< A list of directories in which images are stored.
 
Index: trunk/src/world_entities/environment.cc
===================================================================
--- trunk/src/world_entities/environment.cc	(revision 5307)
+++ trunk/src/world_entities/environment.cc	(revision 5308)
@@ -34,5 +34,5 @@
 {
   this->setClassID(CL_ENVIRONMENT, "Environment");
-  this->model = (Model*)ResourceManager::getInstance()->load("models/ships/bolido.obj", OBJ, RP_CAMPAIGN);
+  this->loadModel("models/ships/bolido.obj");
 
 /*  if(this->obbTree == NULL)
Index: trunk/src/world_entities/skybox.cc
===================================================================
--- trunk/src/world_entities/skybox.cc	(revision 5307)
+++ trunk/src/world_entities/skybox.cc	(revision 5308)
@@ -101,5 +101,5 @@
   for (int i = 0; i < 6; i++)
     delete this->material[i];
-  delete []this->material;
+  delete[] this->material;
   delete this->model;
   this->model = NULL; //< so that WorldEntity does not try to delete it again.
Index: trunk/src/world_entities/terrain.cc
===================================================================
--- trunk/src/world_entities/terrain.cc	(revision 5307)
+++ trunk/src/world_entities/terrain.cc	(revision 5308)
@@ -39,5 +39,6 @@
   this->loadParams(root);
 
-  this->ssp = new SpatialSeparation((AbstractModel*)this->model, 10.0f);
+//  if (this->model != NULL)
+    //this->ssp = new SpatialSeparation((AbstractModel*)this->model, 10.0f);
 }
 
@@ -53,7 +54,7 @@
   this->init();
 
-  if (strstr(fileName, ".obj") || strstr(fileName, ".OBJ"))
-    {
-      this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_LEVEL);
+  if (!strcasestr(fileName, ".obj") )
+    {
+      this->loadModel(fileName);
     }
   else
@@ -65,7 +66,5 @@
 /**
  *  a Constructor for the Debug-Worlds
-
-   @todo make it not compileable when not in debug-mode
-*/
+ */
 Terrain::Terrain(DebugTerrain debugTerrain)
 {
@@ -92,4 +91,5 @@
 
   this->objectList = 0;
+  this->ssp = NULL;
 }
 
@@ -122,5 +122,6 @@
 
   /* THIS IS ONLY FOR DEBUGGING INFORMATION */
-  this->ssp->drawQuadtree();
+  if (this->ssp != NULL)
+    this->ssp->drawQuadtree();
 }
 
@@ -289,4 +290,3 @@
       */
     }
-
-}
+}
Index: trunk/src/world_entities/terrain.h
===================================================================
--- trunk/src/world_entities/terrain.h	(revision 5307)
+++ trunk/src/world_entities/terrain.h	(revision 5308)
@@ -42,5 +42,4 @@
  private:
   int objectList;
-
 };
 
