Index: code/branches/network/src/orxonox/GraphicsEngine.cc
===================================================================
--- code/branches/network/src/orxonox/GraphicsEngine.cc	(revision 928)
+++ code/branches/network/src/orxonox/GraphicsEngine.cc	(revision 929)
@@ -33,4 +33,5 @@
 
 #include <OgreRoot.h>
+#include <OgreException.h>
 #include <OgreConfigFile.h>
 #include <OgreTextureManager.h>
@@ -61,4 +62,6 @@
   GraphicsEngine::~GraphicsEngine()
   {
+    if (!this->root_)
+      delete this->root_;
   }
 
@@ -78,5 +81,5 @@
     root_ = new Root(NULL, configPath_ + "ogre.cfg", configPath_ + "Ogre.log");
 #endif*/
-#if defined(_DEBUG) && defined(WIN32)
+#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && defined(_DEBUG)
     std::string plugin_filename = "plugins_d.cfg";
 #else
@@ -110,8 +113,7 @@
   }
 
-  void GraphicsEngine::startRender()
+  void GraphicsEngine::initialise()
   {
-    root_->initialise(true, "OrxonoxV2");
-    this->renderWindow_ = root_->getAutoCreatedWindow();
+    this->renderWindow_ = root_->initialise(true, "OrxonoxV2");
     TextureManager::getSingleton().setDefaultNumMipmaps(5);
     //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
Index: code/branches/network/src/orxonox/GraphicsEngine.h
===================================================================
--- code/branches/network/src/orxonox/GraphicsEngine.h	(revision 928)
+++ code/branches/network/src/orxonox/GraphicsEngine.h	(revision 929)
@@ -10,9 +10,10 @@
 #include <string>
 
+#include <OgrePrerequisites.h>
 #include <OgreRoot.h>
 #include <OgreSceneManager.h>
 
 #include "OrxonoxPrereqs.h"
-#include "core/BaseObject.h"
+#include "core/OrxonoxClass.h"
 
 
@@ -22,5 +23,5 @@
    * graphics engine manager class
  */
-  class _OrxonoxExport GraphicsEngine : public BaseObject
+  class _OrxonoxExport GraphicsEngine : public OrxonoxClass
   {
     public:
@@ -28,5 +29,5 @@
       inline void setConfigPath(std::string path) { this->configPath_ = path; };
       // find a better way for this
-      inline Ogre::Root* getRoot() { return root_; };
+      //inline Ogre::Root* getRoot() { return root_; };
       void setConfigValues();
       void setup();
@@ -34,12 +35,22 @@
       void loadRessourceLocations(std::string path);
       Ogre::SceneManager* getSceneManager();
-      void startRender();
+      void initialise();
 
       // several window properties
+      Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
       size_t getWindowHandle();
       int getWindowWidth() const;
       int getWindowHeight() const;
 
+      // Ogre Root access for Orxonox
+      void frameStarted(Ogre::FrameEvent &evt)
+      { if (root_) root_->_fireFrameStarted(evt); }
+      void frameEnded  (Ogre::FrameEvent &evt)
+      { if (root_) root_->_fireFrameEnded(evt);   }
+      void renderOneFrame()
+      { if (root_) root_->_updateAllRenderTargets(); }
+
       virtual ~GraphicsEngine();
+
     private:
       Ogre::Root*         root_;        //!< Ogre's root
Index: code/branches/network/src/orxonox/InputHandler.cc
===================================================================
--- code/branches/network/src/orxonox/InputHandler.cc	(revision 928)
+++ code/branches/network/src/orxonox/InputHandler.cc	(revision 929)
@@ -44,10 +44,17 @@
     @brief Constructor only resets the pointer values to 0.
   */
-  InputHandler::InputHandler()
+  InputHandler::InputHandler() :
+      mouse_(0), keyboard_(0), inputSystem_(0),
+      uninitialized_(true)
   {
     //RegisterObject(InputHandler);
-    this->mouse_       = 0;
-    this->keyboard_    = 0;
-    this->inputSystem_ = 0;
+  }
+
+  /**
+    @brief Destructor only called at the end of the program
+  */
+  InputHandler::~InputHandler()
+  {
+    this->destroy();
   }
 
@@ -71,5 +78,5 @@
   void InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight)
   {
-    if (!inputSystem_)
+    if (this->uninitialized_ || !this->inputSystem_)
     {
       // Setup basic variables
@@ -104,4 +111,6 @@
         this->setWindowExtents(windowWidth, windowHeight);
       }
+
+      uninitialized_ = false;
     }
 
@@ -120,9 +129,12 @@
   void InputHandler::destroy()
   {
-    this->inputSystem_->destroyInputObject(this->mouse_);
-    this->inputSystem_->destroyInputObject(this->keyboard_);
-    OIS::InputManager::destroyInputSystem(this->inputSystem_);
-
-    //TODO: If the InputHandler has been destroyed, how does it know?
+    if (!this->inputSystem_)
+    {
+      this->inputSystem_->destroyInputObject(this->mouse_);
+      this->inputSystem_->destroyInputObject(this->keyboard_);
+      OIS::InputManager::destroyInputSystem(this->inputSystem_);
+    }
+
+    this->uninitialized_ = true;
   }
 
Index: code/branches/network/src/orxonox/InputHandler.h
===================================================================
--- code/branches/network/src/orxonox/InputHandler.h	(revision 928)
+++ code/branches/network/src/orxonox/InputHandler.h	(revision 929)
@@ -61,6 +61,7 @@
     // don't mess with a Singleton
     InputHandler ();
-    InputHandler (const InputHandler&) { }
-    ~InputHandler() { }
+    InputHandler (const InputHandler&);
+    InputHandler& operator=(const InputHandler& instance);
+    ~InputHandler();
 
     void callListeners(InputEvent &evt);
@@ -76,4 +77,10 @@
     OIS::Keyboard     *keyboard_;       //!< OIS mouse
     OIS::Mouse        *mouse_;          //!< OIS keyboard
+
+    /**
+      @bref Tells whether initialise has been called successfully
+      Also true if destroy() has been called.
+    */
+    bool uninitialized_;
 
     //! denotes the maximum number of different keys there are in OIS.
Index: code/branches/network/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/network/src/orxonox/Orxonox.cc	(revision 928)
+++ code/branches/network/src/orxonox/Orxonox.cc	(revision 929)
@@ -37,5 +37,4 @@
 //#include <OgreException.h>
 #include <OgreFrameListener.h>
-#include <OgreRoot.h>
 #include <OgreOverlay.h>
 #include <OgreOverlayManager.h>
@@ -86,5 +85,5 @@
     this->auMan_ = 0;
     this->inputHandler_ = 0;
-    this->root_ = 0;
+    //this->root_ = 0;
     // turn on frame smoothing by setting a value different from 0
     this->frameSmoothingTime_ = 0.0f;
@@ -97,6 +96,49 @@
   Orxonox::~Orxonox()
   {
-    // nothing to delete as for now
-    inputHandler_->destroy();
+    // keep in mind: the order of deletion is very important!
+
+    if (this->bulletMgr_)
+      delete this->bulletMgr_;
+    if (this->orxonoxHUD_)
+      delete this->orxonoxHUD_;
+    Loader::close();
+    this->inputHandler_->destroy();
+    if (this->auMan_)
+      delete this->auMan_;
+    if (this->timer_)
+      delete this->timer_;
+    if (this->ogre_)
+      delete this->ogre_;
+
+    if (client_g)
+      delete client_g;
+    if (server_g)
+      delete server_g;
+  }
+
+  /**
+   * error kills orxonox
+   */
+  void Orxonox::abortImmediate(/* some error code */)
+  {
+    //TODO: destroy and destruct everything and print nice error msg
+    delete this;
+  }
+
+  /**
+    Asks the mainloop nicely to abort.
+  */
+  void Orxonox::abortRequest()
+  {
+    bAbort_ = true;
+  }
+
+  /**
+   * @return singleton object
+   */
+  Orxonox* Orxonox::getSingleton()
+  {
+    static Orxonox theOnlyInstance;
+    return &theOnlyInstance;
   }
 
@@ -118,5 +160,5 @@
     ar.checkArgument("data", this->dataPath_, false);
     ar.checkArgument("ip", serverIp_, false);
-    if(ar.errorHandling()) die();
+    if(ar.errorHandling()) abortImmediate();
     if(mode == std::string("client"))
     {
@@ -134,4 +176,38 @@
   }
 
+  void Orxonox::serverInit(std::string path)
+  {
+    COUT(2) << "initialising server" << std::endl;
+    
+    ogre_->setConfigPath(path);
+    ogre_->setup();
+    //root_ = ogre_->getRoot();
+    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
+    
+    server_g = new network::Server();
+  }
+
+  void Orxonox::clientInit(std::string path)
+  {
+    COUT(2) << "initialising client" << std::endl;\
+    
+    ogre_->setConfigPath(path);
+    ogre_->setup();
+    if(serverIp_.compare("")==0)
+      client_g = new network::Client();
+    else
+      client_g = new network::Client(serverIp_, NETWORK_PORT);
+    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
+  }
+  
+  void Orxonox::standaloneInit(std::string path)
+  {
+    COUT(2) << "initialising standalone mode" << std::endl;
+    
+    ogre_->setConfigPath(path);
+    ogre_->setup();
+    //root_ = ogre_->getRoot();
+    if(!ogre_->load(this->dataPath_)) abortImmediate(/* unable to load */);
+  }
   
   /**
@@ -153,5 +229,5 @@
   
   void Orxonox::clientStart(){
-    ogre_->startRender();
+    ogre_->initialise();
     Factory::createClassHierarchy();
     
@@ -179,5 +255,5 @@
   void Orxonox::serverStart(){
     //TODO: start modules
-    ogre_->startRender();
+    ogre_->initialise();
     //TODO: run engine
     Factory::createClassHierarchy();
@@ -192,5 +268,5 @@
   void Orxonox::standaloneStart(){
     //TODO: start modules
-    ogre_->startRender();
+    ogre_->initialise();
     //TODO: run engine
     Factory::createClassHierarchy();
@@ -199,66 +275,4 @@
     
     startRenderLoop();
-  }
-
-  /**
-   * @return singleton object
-   */
-  Orxonox* Orxonox::getSingleton()
-  {
-    static Orxonox theOnlyInstance;
-    return &theOnlyInstance;
-  }
-
-  /**
-   * error kills orxonox
-   */
-  void Orxonox::die(/* some error code */)
-  {
-    //TODO: destroy and destruct everything and print nice error msg
-    delete this;
-  }
-
-  /**
-    Asks the mainloop nicely to abort.
-  */
-  void Orxonox::abortRequest()
-  {
-    bAbort_ = true;
-  }
-
-
-  void Orxonox::serverInit(std::string path)
-  {
-    COUT(2) << "initialising server" << std::endl;
-    
-    ogre_->setConfigPath(path);
-    ogre_->setup();
-    root_ = ogre_->getRoot();
-    if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
-    
-    server_g = new network::Server();
-  }
-
-  void Orxonox::clientInit(std::string path)
-  {
-    COUT(2) << "initialising client" << std::endl;\
-    
-    ogre_->setConfigPath(path);
-    ogre_->setup();
-    if(serverIp_.compare("")==0)
-      client_g = new network::Client();
-    else
-      client_g = new network::Client(serverIp_, NETWORK_PORT);
-    if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
-  }
-  
-  void Orxonox::standaloneInit(std::string path)
-  {
-    COUT(2) << "initialising standalone mode" << std::endl;
-    
-    ogre_->setConfigPath(path);
-    ogre_->setup();
-    root_ = ogre_->getRoot();
-    if(!ogre_->load(this->dataPath_)) die(/* unable to load */);
   }
 
@@ -285,5 +299,6 @@
     auMan_->ambientAdd("a3");
     //auMan->ambientAdd("ambient1");
-    auMan_->ambientStart();*/
+    auMan_->ambientStart();
+  */
   }
 
@@ -316,6 +331,7 @@
   {
     // use the ogre timer class to measure time.
-    Ogre::Timer *timer = new Ogre::Timer();
-    timer->reset();
+    if (!timer_)
+      timer_ = new Ogre::Timer();
+    timer_->reset();
 
     // Contains the times of recently fired events
@@ -331,5 +347,5 @@
 
       // get current time
-      unsigned long now = timer->getMilliseconds();
+      unsigned long now = timer_->getMilliseconds();
 
       // create an event to pass to the frameStarted method in ogre
@@ -341,21 +357,17 @@
       orxonoxHUD_->setTime((int)now, 0);
 
-      // don't forget to call _fireFrameStarted in ogre to make sure
-      // everything goes smoothly
-      if (!ogre_->getRoot()->_fireFrameStarted(evt))
-        break;
-
       // Iterate through all Tickables and call their tick(dt) function
       for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
         (it++)->tick((float)evt.timeSinceLastFrame);
 
+      // don't forget to call _fireFrameStarted in ogre to make sure
+      // everything goes smoothly
+      ogre_->frameStarted(evt);
+
       if (mode_ != SERVER)
-      {
-        // only render in non-server mode
-        ogre_->getRoot()->_updateAllRenderTargets();
-      }
+        ogre_->renderOneFrame(); // only render in non-server mode
 
       // get current time
-      now = timer->getMilliseconds();
+      now = timer_->getMilliseconds();
 
       // create an event to pass to the frameEnded method in ogre
@@ -364,6 +376,5 @@
 
       // again, just to be sure ogre works fine
-      if (!ogre_->getRoot()->_fireFrameEnded(evt))
-        break;
+      ogre_->frameEnded(evt);
 	  }
   }
@@ -406,4 +417,8 @@
   }
 
+  /**
+    @brief Test method for the InputHandler.
+    But: Is actually responsible for catching an exit event..
+  */
   void Orxonox::eventOccured(InputEvent &evt)
   {
Index: code/branches/network/src/orxonox/Orxonox.h
===================================================================
--- code/branches/network/src/orxonox/Orxonox.h	(revision 928)
+++ code/branches/network/src/orxonox/Orxonox.h	(revision 929)
@@ -36,19 +36,25 @@
       void start();
       // not sure if this should be private
-      void die(/* some error code */);
+      void abortImmediate(/* some error code */);
       void abortRequest();
+      inline Ogre::SceneManager*  getSceneManager()        { return ogre_->getSceneManager(); };
+      inline GraphicsEngine*      getOgrePointer()         { return ogre_; };
+      inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
+      inline BulletManager*       getBulletMgr()           { return this->bulletMgr_; }
+
       static Orxonox* getSingleton();
-      inline Ogre::SceneManager* getSceneManager()         { return ogre_->getSceneManager(); };
-      inline GraphicsEngine* getOgrePointer()              { return ogre_; };
-      inline audio::AudioManager* getAudioManagerPointer() { return auMan_; };
-      inline BulletManager* getBulletMgr()                 { return this->bulletMgr_; }
 
-    private:
+   private:
+      // don't mess with singletons
       Orxonox();
-      virtual ~Orxonox();
+      Orxonox(Orxonox& instance);
+      Orxonox& operator=(const Orxonox& instance);
+      ~Orxonox();
+
       // init functions
       void serverInit(std::string path);
       void clientInit(std::string path);
       void standaloneInit(std::string path);
+
       // run functions
       void serverStart();
@@ -56,5 +62,5 @@
       void standaloneStart();
 
-      void createScene(void);
+      void createScene();
       void setupInputSystem();
       void startRenderLoop();
@@ -68,6 +74,7 @@
       audio::AudioManager*  auMan_;         //!< audio manager
       BulletManager*        bulletMgr_;     //!< Keeps track of the thrown bullets
-      InputHandler*         inputHandler_;
-      Ogre::Root*           root_;
+      InputHandler*         inputHandler_;  //!< Handles input with key bindings
+      Ogre::Root*           root_;          //!< Holy grail of Ogre
+      Ogre::Timer*          timer_;         //!< Main loop timer
       // TODO: make this a config-value by creating a config class for orxonox
       float                 frameSmoothingTime_;
Index: code/branches/network/src/orxonox/objects/Camera.cc
===================================================================
--- code/branches/network/src/orxonox/objects/Camera.cc	(revision 928)
+++ code/branches/network/src/orxonox/objects/Camera.cc	(revision 929)
@@ -6,5 +6,4 @@
 #include <OgreSceneManager.h>
 #include <OgreSceneNode.h>
-#include <OgreRoot.h>
 #include <OgreRenderWindow.h>
 #include <OgreViewport.h>
@@ -69,5 +68,5 @@
 
         // FIXME: unused var
-        Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
+        Ogre::Viewport* vp = orxonox::Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
 
 
Index: code/branches/network/src/orxonox/objects/Fighter.cc
===================================================================
--- code/branches/network/src/orxonox/objects/Fighter.cc	(revision 928)
+++ code/branches/network/src/orxonox/objects/Fighter.cc	(revision 929)
@@ -208,5 +208,5 @@
 
             node->attachObject(cam);
-            Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
+            Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
     	}
     }
Index: code/branches/network/src/orxonox/objects/SpaceShip.cc
===================================================================
--- code/branches/network/src/orxonox/objects/SpaceShip.cc	(revision 928)
+++ code/branches/network/src/orxonox/objects/SpaceShip.cc	(revision 929)
@@ -286,5 +286,5 @@
 
         this->camNode_->attachObject(cam);
-        Orxonox::getSingleton()->getOgrePointer()->getRoot()->getAutoCreatedWindow()->addViewport(cam);
+        Orxonox::getSingleton()->getOgrePointer()->getRenderWindow()->addViewport(cam);
     }
 
