Index: code/branches/network/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/network/src/orxonox/CMakeLists.txt	(revision 933)
+++ code/branches/network/src/orxonox/CMakeLists.txt	(revision 934)
@@ -1,6 +1,6 @@
 SET( ORXONOX_SRC_FILES
   GraphicsEngine.cc
+  InputEventListener.cc
   InputHandler.cc
-  InputEventListener.cc
   Main.cc
   Orxonox.cc
Index: code/branches/network/src/orxonox/InputHandler.cc
===================================================================
--- code/branches/network/src/orxonox/InputHandler.cc	(revision 933)
+++ code/branches/network/src/orxonox/InputHandler.cc	(revision 934)
@@ -22,5 +22,5 @@
  *      Reto Grieder
  *   Co-authors:
- *      Some guy writing the example code from Ogre
+ *      ...
  *
  */
@@ -35,4 +35,5 @@
 
 #include "core/CoreIncludes.h"
+#include "core/Debug.h"
 #include "Orxonox.h"
 #include "InputEventListener.h"
@@ -42,9 +43,13 @@
 {
   /**
+    @brief The reference to the singleton
+  */
+  InputHandler* InputHandler::singletonRef_s = 0;
+
+  /**
     @brief Constructor only resets the pointer values to 0.
   */
   InputHandler::InputHandler() :
-      mouse_(0), keyboard_(0), inputSystem_(0),
-      uninitialized_(true)
+      mouse_(0), keyboard_(0), inputSystem_(0)
   {
     //RegisterObject(InputHandler);
@@ -56,5 +61,4 @@
   InputHandler::~InputHandler()
   {
-    this->destroy();
   }
 
@@ -65,6 +69,9 @@
   InputHandler *InputHandler::getSingleton()
   {
-    static InputHandler theOnlyInstance;
-    return &theOnlyInstance;
+    if (!singletonRef_s)
+      singletonRef_s = new InputHandler();
+    return singletonRef_s;
+    //static InputHandler theOnlyInstance;
+    //return &theOnlyInstance;
   }
 
@@ -76,7 +83,7 @@
     @param windowHeight The height of the render window
   */
-  void InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight)
-  {
-    if (this->uninitialized_ || !this->inputSystem_)
+  bool InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight)
+  {
+    if (!this->inputSystem_)
     {
       // Setup basic variables
@@ -92,27 +99,43 @@
 #endif
 
-      // Create inputsystem
-      inputSystem_ = OIS::InputManager::createInputSystem(paramList);
-
-      // If possible create a buffered keyboard
-      if (inputSystem_->numKeyboards() > 0)
+      try
       {
-        keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
-        keyboard_->setEventCallback(this);
+        // Create inputsystem
+        inputSystem_ = OIS::InputManager::createInputSystem(paramList);
+        //if (getSoftDebugLevel() >= ORX_DEBUG)
+        //  orxonox::OutputHandler::getOutStream().setOutputLevel(4) << "asdfblah" << std::endl;
+        COUT(ORX_DEBUG) << "*** InputHandler: Created OIS input system" << std::endl;
+
+        // If possible create a buffered keyboard
+        if (inputSystem_->numKeyboards() > 0)
+        {
+          keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
+          keyboard_->setEventCallback(this);
+          COUT(ORX_DEBUG) << "*** InputHandler: Created OIS mouse" << std::endl;
+        }
+
+        // If possible create a buffered mouse
+        if (inputSystem_->numMice() > 0 )
+        {
+          mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
+          mouse_->setEventCallback(this);
+          COUT(ORX_DEBUG) << "*** InputHandler: Created OIS keyboard" << std::endl;
+
+          // Set mouse region
+          this->setWindowExtents(windowWidth, windowHeight);
+        }
       }
-
-      // If possible create a buffered mouse
-      if (inputSystem_->numMice() > 0 )
+      catch (OIS::Exception ex)
       {
-        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
-        mouse_->setEventCallback(this);
-
-        // Set mouse region
-        this->setWindowExtents(windowWidth, windowHeight);
+        // something went wrong with the initialisation
+        COUT(ORX_ERROR) << "Error: Failed creating an input system. Message: \"" << ex.eText << "\"" << std::endl;
+        this->inputSystem_ = 0;
+        return false;
       }
-
-      uninitialized_ = false;
     }
 
+    COUT(ORX_DEBUG) << "*** InputHandler: Loading key bindings..." << std::endl;
+    // temporary solution: create event list
+    //InputEvent[] list = this->createEventList();
     // load the key bindings
     InputEvent empty = {0, false, 0, 0, 0};
@@ -122,4 +145,7 @@
     //assign 'abort' to the escape key
     this->bindingsKeyPressed_[(int)OIS::KC_ESCAPE].id = 1;
+    COUT(ORX_DEBUG) << "*** InputHandler: Loading done." << std::endl;
+
+    return true;
   }
 
@@ -127,6 +153,7 @@
     @brief Destroys all the created input devices.
   */
-  void InputHandler::destroy()
-  {
+  void InputHandler::destroyDevices()
+  {
+    COUT(ORX_DEBUG) << "*** InputHandler: Destroying InputHandler..." << std::endl;
     if (this->mouse_)
       this->inputSystem_->destroyInputObject(mouse_);
@@ -139,5 +166,15 @@
     this->keyboard_      = 0;
     this->inputSystem_   = 0;
-    this->uninitialized_ = true;
+    COUT(ORX_DEBUG) << "*** InputHandler: Destroying done." << std::endl;
+  }
+
+  /**
+    @brief Destroys the singleton.
+  */
+  void InputHandler::destroy()
+  {
+    if (singletonRef_s)
+      delete singletonRef_s;
+    singletonRef_s = 0;
   }
 
Index: code/branches/network/src/orxonox/InputHandler.h
===================================================================
--- code/branches/network/src/orxonox/InputHandler.h	(revision 933)
+++ code/branches/network/src/orxonox/InputHandler.h	(revision 934)
@@ -43,18 +43,25 @@
 namespace orxonox
 {
+  /**
+    @brief Captures and distributes mouse and keyboard input.
+    It resolves the key bindings to InputEvents which can be heard by
+    implementing the InputEventListener interface.
+  */
   class _OrxonoxExport InputHandler
         : public Tickable, public OIS::KeyListener, public OIS::MouseListener
   {
-    //friend ClassIdentifier<InputHandler>;
+    //friend class ClassIdentifier<InputHandler>;
   public:
-    void initialise(size_t windowHnd, int windowWidth, int windowHeight);
-    void destroy();
+    bool initialise(size_t windowHnd, int windowWidth, int windowHeight);
+    void destroyDevices();
     void tick(float dt);
     void setWindowExtents(int width, int height);
 
+    // Temporary solutions. Will be removed soon!
     OIS::Mouse    *getMouse()    { return this->mouse_   ; }
     OIS::Keyboard *getKeyboard() { return this->keyboard_; }
 
     static InputHandler* getSingleton();
+    static void destroy();
 
   private:
@@ -78,12 +85,6 @@
     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.
-    //! 256 should be ok since the highest number in the enum is 237.
+    /** denotes the maximum number of different keys there are in OIS.
+        256 should be ok since the highest number in the enum is 237. */
     static const int numberOfKeys_ = 256;
     //! Array of input events for every pressed key
@@ -92,6 +93,6 @@
     InputEvent bindingsKeyReleased_[numberOfKeys_];
 
-    //! denotes the maximum number of different buttons there are in OIS.
-    //! 16 should be ok since the highest number in the enum is 7.
+    /** denotes the maximum number of different buttons there are in OIS.
+        16 should be ok since the highest number in the enum is 7. */
     static const int numberOfButtons_ = 16;
     //! Array of input events for every pressed key
@@ -100,4 +101,6 @@
     InputEvent bindingsButtonReleased_[numberOfButtons_];
 
+    //! Pointer to the instance of the singleton
+    static InputHandler *singletonRef_s;
   };
 }
Index: code/branches/network/src/orxonox/Main.cc
===================================================================
--- code/branches/network/src/orxonox/Main.cc	(revision 933)
+++ code/branches/network/src/orxonox/Main.cc	(revision 934)
@@ -27,19 +27,18 @@
 
  /**
- @file  Main.cc
- @brief main file handling most of the machine specific code
+ @file
+ @brief Entry point of the program. Platform specific code.
   */
 
 #include "OrxonoxStableHeaders.h"
 
-#include <OgrePlatform.h>
-#include <OgreException.h>
+#include <exception>
 
-
+#include "OrxonoxPlatform.h"
 #include "core/SignalHandler.h"
 #include "Orxonox.h"
 
 using namespace orxonox;
-#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
+#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
 #include <CoreFoundation/CoreFoundation.h>
 
@@ -72,133 +71,23 @@
 #endif
 
-#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined( __MINGW32__ )
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#include <windows.h>
-  INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
-  {
-    // something like this would be less hacky
-    // maybe one can work with trailing '\0'
-    // or maybe use string based functions
-    // I was unable to test it without working windows version
-    char* cmd = strCmdLine;
-    int argc = 2;
-    int i;
-    int j;
-    for(i = 0; cmd[i] != NULL; i++)
-    {
-      if(cmd[i] == ' ') argc++;
-    }
-    char **argv = new char*[argc];
-    for (j = 0; j < argc; j++)
-    {
-      argv[j] = new char[i];
-    }
-    j = 1;
-    int k = 0;
-    for(int i = 0; cmd[i] != NULL; i++)
-    {
-      if(cmd[i] != ' ') {
-        argv[j][k] = cmd[i];
-        k++;
-      }
-      else {
-        argv[j][k] = '\0';
-        k = 0;
-        j++;
-      }
-    }
-    argv[j][k] = '\0';
-    argv[0] = "BeniXonox.exe";
-    //char *argv[2];
-    //argv[0] = "asdfProgram";
-    //argv[1] =  strCmdLine;
-    //int argc = 2;
+int main(int argc, char **argv)
+{
+  try {
+    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
+    Orxonox* orx = Orxonox::getSingleton();
+
+#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE
+    orx->init(argc, argv, macBundlePath());
 #else
-  int main(int argc, char **argv)
-  {
-#endif
-    try {
-      srand(time(0));  //initaialize RNG; TODO check if it works on win
-      SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
-      Orxonox* orx = Orxonox::getSingleton();
-#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
-      orx->init(argc, argv, macBundlePath());
-      orx->start();
-#else
-/*
-for (int i = 0; i < 500; i++)
-{
-int x = rand() % 40000 - 20000;
-int y = rand() % 40000 - 20000;
-int z = rand() % 40000 - 20000;
-
-int scale = rand() % 100 + 20;
-
-int version = rand() % 6 + 1;
-
-float rotx = float(rand()) / RAND_MAX;
-float roty = float(rand()) / RAND_MAX;
-float rotz = float(rand()) / RAND_MAX;
-
-int axis = rand() % 3 + 1;
-
-if (axis == 1)
-  rotx = 0;
-if (axis == 2)
-  roty = 0;
-if (axis == 3)
-  rotz = 0;
-
-int rotation = rand() % 40 + 10;
-
-//    <Model position="1000,1500,0" scale="50" mesh="ast1.mesh" rotationAxis="0,1.25,0" rotationRate="70" />
-std::cout << "    <Model position=\"" << x << "," << y << "," << z << "\" scale=\"" << scale << "\" mesh=\"ast" << version << ".mesh\" rotationAxis=\"" << rotx << "," << roty << "," << rotz << "\" rotationRate=\"" << rotation << "\" />" << std::endl;
-
-
-}
-*/
-      orx->init(argc, argv, "");
-      orx->start();
-#endif
-    }
-    catch (Ogre::Exception& e) {
-#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined( __MINGW32__ )
-      MessageBoxA(NULL, e.getFullDescription().c_str(),
-            "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
-#else
-      std::cerr << "Exception:\n";
-      std::cerr << e.getFullDescription().c_str() << "\n";
-#endif
-      return 1;
-    }
-    return 0;
-  }
-
-#ifdef __cplusplus
-}
+    orx->init(argc, argv, "");
 #endif
 
-
-/*int main(int argc, char **argv)
-{
-  try
+    orx->start();
+    orx->destroy();
+  }
+  catch (std::exception &ex)
   {
-    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
-    Orxonox* orx = Orxonox::getSingleton();
-#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
-    orx->init(argc, argv, macBundlePath());
-    orx->start();
-#else
-    orx->init(argc, argv, "");
-    orx->start();
-#endif
-
-  }
-  catch(Ogre::Exception& e)
-  {
-    fprintf(stderr, "An exception has occurred: %s\n",
-            e.getFullDescription().c_str());
+    std::cerr << "Exception:\n";
+    std::cerr << ex.what() << "\n";
     return 1;
   }
@@ -207,3 +96,5 @@
 }
 
-*/
+#ifdef __cplusplus
+}
+#endif
Index: code/branches/network/src/orxonox/Orxonox.cc
===================================================================
--- code/branches/network/src/orxonox/Orxonox.cc	(revision 933)
+++ code/branches/network/src/orxonox/Orxonox.cc	(revision 934)
@@ -46,7 +46,4 @@
 //#include <exception>
 #include <deque>
-#define _CRTDBG_MAP_ALLOC
-#include <stdlib.h>
-#include <crtdbg.h>
 
 //***** ORXONOX ****
@@ -80,4 +77,9 @@
 {
   /**
+    @brief Reference to the only instance of the class.
+  */
+  Orxonox *Orxonox::singletonRef_s = 0;
+
+  /**
    * create a new instance of Orxonox
    */
@@ -85,4 +87,5 @@
   {
     this->ogre_ = new GraphicsEngine();
+    this->timer_ = 0;
     this->dataPath_ = "";
     this->auMan_ = 0;
@@ -105,6 +108,5 @@
       delete this->orxonoxHUD_;
     Loader::close();
-    // do not destroy the InputHandler since this is a singleton too
-    // and might have been deleted already (after return 0; in main())
+    InputHandler::destroy();
     if (this->auMan_)
       delete this->auMan_;
@@ -142,6 +144,19 @@
   Orxonox* Orxonox::getSingleton()
   {
-    static Orxonox theOnlyInstance;
-    return &theOnlyInstance;
+    if (!singletonRef_s)
+      singletonRef_s = new Orxonox();
+    return singletonRef_s;
+    //static Orxonox theOnlyInstance;
+    //return &theOnlyInstance;
+  }
+
+  /**
+    @brief Destroys the Orxonox singleton.
+  */
+  void Orxonox::destroy()
+  {
+    if (singletonRef_s)
+      delete singletonRef_s;
+    singletonRef_s = 0;
   }
 
@@ -313,6 +328,7 @@
   {
     inputHandler_ = InputHandler::getSingleton();
-    inputHandler_->initialise(ogre_->getWindowHandle(),
-          ogre_->getWindowWidth(), ogre_->getWindowHeight());
+    if (!inputHandler_->initialise(ogre_->getWindowHandle(),
+          ogre_->getWindowWidth(), ogre_->getWindowHeight()))
+      abortImmediate();
   }
 
Index: code/branches/network/src/orxonox/Orxonox.h
===================================================================
--- code/branches/network/src/orxonox/Orxonox.h	(revision 933)
+++ code/branches/network/src/orxonox/Orxonox.h	(revision 934)
@@ -44,4 +44,5 @@
 
       static Orxonox* getSingleton();
+      static void destroy();
 
    private:
@@ -86,4 +87,6 @@
       gameMode              mode_;
       std::string           serverIp_;
+
+      static Orxonox *singletonRef_s;
   };
 }
Index: code/branches/network/src/orxonox/core/DebugLevel.cc
===================================================================
--- code/branches/network/src/orxonox/core/DebugLevel.cc	(revision 933)
+++ code/branches/network/src/orxonox/core/DebugLevel.cc	(revision 934)
@@ -95,5 +95,5 @@
 
         // Return a constant value while we're creating the object
-        return 4;
+        return 3;
     }
 }
