Index: /code/branches/core5/src/libraries/core/Core.cc
===================================================================
--- /code/branches/core5/src/libraries/core/Core.cc	(revision 5876)
+++ /code/branches/core5/src/libraries/core/Core.cc	(revision 5877)
@@ -434,5 +434,5 @@
     {
         // singletons from other libraries
-        ScopedSingletonManager::update(time, ScopeID::Root);
+        ScopedSingletonManager::update<ScopeID::Root>(time);
         if (this->bGraphicsLoaded_)
         {
@@ -442,5 +442,5 @@
             this->guiManager_->update(time);
             // graphics singletons from other libraries
-            ScopedSingletonManager::update(time, ScopeID::Graphics);
+            ScopedSingletonManager::update<ScopeID::Graphics>(time);
         }
         // process thread commands
Index: /code/branches/core5/src/libraries/core/ScopedSingletonManager.h
===================================================================
--- /code/branches/core5/src/libraries/core/ScopedSingletonManager.h	(revision 5876)
+++ /code/branches/core5/src/libraries/core/ScopedSingletonManager.h	(revision 5877)
@@ -34,9 +34,10 @@
 #include <cassert>
 #include <map>
+#include "util/Exception.h"
 #include "util/Scope.h"
 #include "util/Singleton.h"
 
-#define ManageScopedSingleton(className, scope) \
-    static ClassScopedSingletonManager<className, scope> className##ScopedSingletonManager(#className)
+#define ManageScopedSingleton(className, scope, allowedToFail) \
+    static ClassScopedSingletonManager<className, scope, allowedToFail> className##ScopedSingletonManager(#className)
 
 namespace orxonox
@@ -53,6 +54,8 @@
             static void removeManager(ScopedSingletonManager* manager);
 
-            static void update(const Clock& time, ScopeID::Value scope)
+            template<ScopeID::Value scope>
+            static void update(const Clock& time)
             {
+                assert(Scope<scope>::isActive());
                 for (ManagerMultiMap::iterator it = getManagersByScope().lower_bound(scope); it != getManagersByScope().upper_bound(scope); ++it)
                     it->second->update(time);
@@ -69,5 +72,5 @@
     };
 
-    template <class T, ScopeID::Value scope>
+    template <class T, ScopeID::Value scope, bool allowedToFail>
     class ClassScopedSingletonManager : public ScopedSingletonManager, public ScopeListener
     {
@@ -83,4 +86,5 @@
         ~ClassScopedSingletonManager()
         {
+            assert(singletonPtr_ == NULL);
             ScopedSingletonManager::removeManager(this);
         }
@@ -101,4 +105,63 @@
         }
 
+        void destroy(OrxonoxClass*)
+        {
+            singletonPtr_->destroy();
+        }
+        void destroy(void*)
+        {
+            delete singletonPtr_;
+        }
+
+        //! Called every frame by the ScopedSingletonManager
+        void update(const Clock& time)
+        {
+            assert(Scope<scope>::isActive());
+            // assuming T inherits Singleton<T>
+            singletonPtr_->updateSingleton(time);
+        }
+
+    private:
+        T* singletonPtr_;
+    };
+
+    template <class T, ScopeID::Value scope>
+    class ClassScopedSingletonManager<T, scope, true> : public ScopedSingletonManager, public ScopeListener
+    {
+    public:
+        ClassScopedSingletonManager(const std::string& className)
+            : ScopedSingletonManager(className, scope)
+            , ScopeListener(scope)
+            , singletonPtr_(NULL)
+        {
+            ScopedSingletonManager::addManager(this);
+        }
+
+        ~ClassScopedSingletonManager()
+        {
+            assert(singletonPtr_ == NULL);
+            ScopedSingletonManager::removeManager(this);
+        }
+
+        //! Called if the Scope of the Singleton gets active (creates the instance)
+        void activated()
+        {
+            assert(singletonPtr_ == NULL);
+            try
+                { singletonPtr_ = new T(); }
+            catch (...)
+                { COUT(1) << "Singleton creation failed: " << Exception::handleMessage() << std::endl; }
+        }
+
+        //! Called if the Scope of this Singleton gets deactivated (destroys the instance)
+        void deactivated()
+        {
+            if (singletonPtr_ != NULL)
+            {
+                this->destroy(singletonPtr_);
+                singletonPtr_ = NULL;
+            }
+        }
+
         void destroy(OrxonoxClass* ptr)
         {
@@ -113,6 +176,8 @@
         void update(const Clock& time)
         {
+            assert(Scope<scope>::isActive());
             // assuming T inherits Singleton<T>
-            singletonPtr_->updateSingleton(time);
+            if (singletonPtr_ != NULL)
+                singletonPtr_->updateSingleton(time);
         }
 
Index: /code/branches/core5/src/libraries/core/input/KeyBinderManager.cc
===================================================================
--- /code/branches/core5/src/libraries/core/input/KeyBinderManager.cc	(revision 5876)
+++ /code/branches/core5/src/libraries/core/input/KeyBinderManager.cc	(revision 5877)
@@ -41,5 +41,5 @@
 {
     KeyBinderManager* KeyBinderManager::singletonPtr_s = 0;
-    ManageScopedSingleton(KeyBinderManager, ScopeID::Graphics);
+    ManageScopedSingleton(KeyBinderManager, ScopeID::Graphics, false);
 
     KeyBinderManager::KeyBinderManager()
Index: /code/branches/core5/src/libraries/core/input/KeyDetector.cc
===================================================================
--- /code/branches/core5/src/libraries/core/input/KeyDetector.cc	(revision 5876)
+++ /code/branches/core5/src/libraries/core/input/KeyDetector.cc	(revision 5877)
@@ -40,5 +40,5 @@
     std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
     KeyDetector* KeyDetector::singletonPtr_s = 0;
-    ManageScopedSingleton(KeyDetector, ScopeID::Graphics);
+    ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false);
 
     KeyDetector::KeyDetector()
Index: /code/branches/core5/src/libraries/util/Scope.h
===================================================================
--- /code/branches/core5/src/libraries/util/Scope.h	(revision 5876)
+++ /code/branches/core5/src/libraries/util/Scope.h	(revision 5877)
@@ -35,5 +35,7 @@
 #include <map>
 #include <set>
+
 #include "Debug.h"
+#include "ScopeGuard.h"
 
 namespace orxonox
@@ -63,5 +65,5 @@
         protected:
             //! Constructor: Registers the instance.
-            ScopeListener(ScopeID::Value scope) : scope_(scope)
+            ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false)
                 { ScopeManager::listeners_s[this->scope_].insert(this); }
             //! Destructor: Unregisters the instance.
@@ -76,4 +78,5 @@
         private:
             ScopeID::Value scope_; //!< Store the scope to unregister on destruction
+            bool bActivated_;
     };
 
@@ -91,10 +94,23 @@
             Scope()
             {
-                ScopeManager::instanceCounts_s[scope]++;
-                assert(ScopeManager::instanceCounts_s[scope] > 0);
-                if (ScopeManager::instanceCounts_s[scope] == 1)
+                try
                 {
-                    for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
-                        (*(it++))->activated();
+                    ScopeManager::instanceCounts_s[scope]++;
+                    assert(ScopeManager::instanceCounts_s[scope] > 0);
+                    if (ScopeManager::instanceCounts_s[scope] == 1)
+                    {
+                        Loki::ScopeGuard deactivator = Loki::MakeObjGuard(*this, &Scope::deactivateListeners);
+                        for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
+                        {
+                            (*it)->activated();
+                            (*(it++))->bActivated_ = true;
+                        }
+                        deactivator.Dismiss();
+                    }
+                }
+                catch (...)
+                {
+                    ScopeManager::instanceCounts_s[scope]--;
+                    throw;
                 }
             }
@@ -111,7 +127,21 @@
 
                 if (ScopeManager::instanceCounts_s[scope] == 0)
+                    this->deactivateListeners();
+            }
+
+            void deactivateListeners()
+            {
+                for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
                 {
-                    for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); )
-                        (*(it++))->deactivated();
+                    if ((*it)->bActivated_)
+                    {
+                        try
+                            { (*it)->deactivated(); }
+                        catch (...)
+                            { COUT(0) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << std::endl; }
+                        (*(it++))->bActivated_ = false;
+                    }
+                    else
+                        ++it;
                 }
             }
Index: /code/branches/core5/src/modules/questsystem/QuestManager.cc
===================================================================
--- /code/branches/core5/src/modules/questsystem/QuestManager.cc	(revision 5876)
+++ /code/branches/core5/src/modules/questsystem/QuestManager.cc	(revision 5877)
@@ -57,5 +57,5 @@
     //! Pointer to the current (and single) instance of this class.
     /*static*/ QuestManager* QuestManager::singletonPtr_s = NULL;
-    ManageScopedSingleton(QuestManager, ScopeID::Root);
+    ManageScopedSingleton(QuestManager, ScopeID::Root, false);
 
     /**
Index: /code/branches/core5/src/modules/questsystem/notifications/NotificationManager.cc
===================================================================
--- /code/branches/core5/src/modules/questsystem/notifications/NotificationManager.cc	(revision 5876)
+++ /code/branches/core5/src/modules/questsystem/notifications/NotificationManager.cc	(revision 5877)
@@ -48,5 +48,5 @@
 
     NotificationManager* NotificationManager::singletonPtr_s = NULL;
-    ManageScopedSingleton(NotificationManager, ScopeID::Root);
+    ManageScopedSingleton(NotificationManager, ScopeID::Root, false);
 
     /**
Index: /code/branches/core5/src/orxonox/CameraManager.cc
===================================================================
--- /code/branches/core5/src/orxonox/CameraManager.cc	(revision 5876)
+++ /code/branches/core5/src/orxonox/CameraManager.cc	(revision 5877)
@@ -45,6 +45,6 @@
 namespace orxonox
 {
-    ManageScopedSingleton(CameraManager, ScopeID::Graphics);
     CameraManager* CameraManager::singletonPtr_s = 0;
+    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
 
     CameraManager::CameraManager()
Index: /code/branches/core5/src/orxonox/LevelManager.cc
===================================================================
--- /code/branches/core5/src/orxonox/LevelManager.cc	(revision 5876)
+++ /code/branches/core5/src/orxonox/LevelManager.cc	(revision 5877)
@@ -44,6 +44,6 @@
     SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
 
-    ManageScopedSingleton(LevelManager, ScopeID::Root);
     LevelManager* LevelManager::singletonPtr_s = 0;
+    ManageScopedSingleton(LevelManager, ScopeID::Root, false);
 
     LevelManager::LevelManager()
Index: /code/branches/core5/src/orxonox/PlayerManager.cc
===================================================================
--- /code/branches/core5/src/orxonox/PlayerManager.cc	(revision 5876)
+++ /code/branches/core5/src/orxonox/PlayerManager.cc	(revision 5877)
@@ -39,5 +39,5 @@
 {
     PlayerManager* PlayerManager::singletonPtr_s = 0;
-    ManageScopedSingleton(PlayerManager, ScopeID::Root);
+    ManageScopedSingleton(PlayerManager, ScopeID::Root, false);
 
     PlayerManager::PlayerManager()
Index: /code/branches/core5/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- /code/branches/core5/src/orxonox/overlays/InGameConsole.cc	(revision 5876)
+++ /code/branches/core5/src/orxonox/overlays/InGameConsole.cc	(revision 5877)
@@ -62,5 +62,5 @@
 
     InGameConsole* InGameConsole::singletonPtr_s = 0;
-    ManageScopedSingleton(InGameConsole, ScopeID::Graphics);
+    ManageScopedSingleton(InGameConsole, ScopeID::Graphics, false);
 
     /**
Index: /code/branches/core5/src/orxonox/sound/SoundManager.cc
===================================================================
--- /code/branches/core5/src/orxonox/sound/SoundManager.cc	(revision 5876)
+++ /code/branches/core5/src/orxonox/sound/SoundManager.cc	(revision 5877)
@@ -40,5 +40,5 @@
 {
     SoundManager* SoundManager::singletonPtr_s = NULL;
-    ManageScopedSingleton(SoundManager, ScopeID::Graphics);
+    ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
 
     /**
