Index: orxonox/trunk/src/glmenu/glmenu_imagescreen.cc
===================================================================
--- orxonox/trunk/src/glmenu/glmenu_imagescreen.cc	(revision 3676)
+++ orxonox/trunk/src/glmenu/glmenu_imagescreen.cc	(revision 3677)
@@ -41,4 +41,5 @@
 {
    this->setClassName ("GLMenuImageScreen");
+   this->backMat = NULL;
 }
 
@@ -50,6 +51,6 @@
 GLMenuImageScreen::~GLMenuImageScreen() 
 {
-  if (backMat)
-    delete backMat;
+  if (this->backMat)
+    delete this->backMat;
 }
 
Index: orxonox/trunk/src/lib/util/resource_manager.cc
===================================================================
--- orxonox/trunk/src/lib/util/resource_manager.cc	(revision 3676)
+++ orxonox/trunk/src/lib/util/resource_manager.cc	(revision 3677)
@@ -175,5 +175,12 @@
   // searching if the resource was loaded before.
   Resource* tmpResource = this->locateResourceByName(fileName);
-  if (!tmpResource) // if the resource was not loaded before.
+  if (tmpResource) // if the resource was not loaded before.
+    {
+      PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
+      tmpResource->count++;
+      if(tmpResource->prio < prio)
+	tmpResource->prio = prio;
+    }
+  else
     {
       char* tmpDir;
@@ -252,11 +259,4 @@
       delete []fullName;
     }
-  else
-    {
-      PRINTF(4)("not loading cached resource %s\n", tmpResource->name);
-      tmpResource->count++;
-      if(tmpResource->prio < prio)
-	tmpResource->prio = prio;
-    }
 
   return tmpResource->pointer;
@@ -330,5 +330,9 @@
     {
       if (enumRes->prio <= prio)
-	unload(enumRes, prio);
+	if (enumRes->count == 0)
+	  unload(enumRes, prio);
+	else
+	  PRINTF(2)("unable to unload %s because there are still %d references to it\n",
+		   enumRes->name, enumRes->count);
       //enumRes = resourceList->nextElement();
       enumRes = iterator->nextElement();
Index: orxonox/trunk/src/story_entities/world.cc
===================================================================
--- orxonox/trunk/src/story_entities/world.cc	(revision 3676)
+++ orxonox/trunk/src/story_entities/world.cc	(revision 3677)
@@ -145,7 +145,8 @@
   cn->unbind(this->localPlayer);
   cn->reset();
+
   ResourceManager::getInstance()->debug();
-
   ResourceManager::getInstance()->unloadAllByPriority(RP_LEVEL);
+  ResourceManager::getInstance()->debug();
 
   delete WorldInterface::getInstance();
Index: orxonox/trunk/src/world_entities/primitive.cc
===================================================================
--- orxonox/trunk/src/world_entities/primitive.cc	(revision 3676)
+++ orxonox/trunk/src/world_entities/primitive.cc	(revision 3677)
@@ -21,5 +21,5 @@
 #include "stdincl.h"
 #include "world_entity.h"
-#include "objModel.h"
+#include "model.h"
 #include "vector.h"
 
Index: orxonox/trunk/src/world_entities/terrain.cc
===================================================================
--- orxonox/trunk/src/world_entities/terrain.cc	(revision 3676)
+++ orxonox/trunk/src/world_entities/terrain.cc	(revision 3677)
@@ -17,5 +17,5 @@
 #include "terrain.h"
 #include "stdincl.h"
-#include "objModel.h"
+#include "model.h"
 #include "vector.h"
 #include "glincl.h"
@@ -45,5 +45,5 @@
   if (strstr(fileName, ".obj") || strstr(fileName, ".OBJ"))
     {
-      this->model = (OBJModel*)new OBJModel(fileName);
+      this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_LEVEL);
     }
   else
Index: orxonox/trunk/src/world_entities/test_gun.cc
===================================================================
--- orxonox/trunk/src/world_entities/test_gun.cc	(revision 3676)
+++ orxonox/trunk/src/world_entities/test_gun.cc	(revision 3677)
@@ -25,5 +25,5 @@
 #include "stdincl.h"
 #include "world_entity.h"
-#include "objModel.h"
+#include "model.h"
 #include "projectile.h"
 
Index: orxonox/trunk/src/world_entities/weapon.cc
===================================================================
--- orxonox/trunk/src/world_entities/weapon.cc	(revision 3676)
+++ orxonox/trunk/src/world_entities/weapon.cc	(revision 3677)
@@ -21,5 +21,5 @@
 #include "world_entity.h"
 #include "vector.h"
-#include "objModel.h"
+#include "model.h"
 #include "projectile.h"
 #include "list.h"
