Index: code/branches/network/src/orxonox/InputHandler.cc
===================================================================
--- code/branches/network/src/orxonox/InputHandler.cc	(revision 930)
+++ 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;
   }
 
