Index: code/branches/gui/src/core/Loader.cc
===================================================================
--- code/branches/gui/src/core/Loader.cc	(revision 1645)
+++ code/branches/gui/src/core/Loader.cc	(revision 1646)
@@ -64,4 +64,6 @@
     void Loader::add(const Level* level, const ClassTreeMask& mask)
     {
+        if (!level)
+            return;
         Loader::levels_s.insert(Loader::levels_s.end(), std::pair<const Level*, ClassTreeMask>(level, mask));
     }
@@ -69,4 +71,6 @@
     void Loader::remove(const Level* level)
     {
+        if (!level)
+            return;
         for (std::vector<std::pair<const Level*, ClassTreeMask> >::iterator it = Loader::levels_s.begin(); it != Loader::levels_s.end(); ++it)
         {
@@ -108,4 +112,7 @@
     bool Loader::load(const Level* level, const ClassTreeMask& mask)
     {
+        if (!level)
+            return false;
+
         Loader::currentMask_s = level->getMask() * mask;
 
@@ -165,4 +172,6 @@
     void Loader::unload(const Level* level, const ClassTreeMask& mask)
     {
+        if (!level)
+            return;
         for (Iterator<BaseObject> it = ObjectList<BaseObject>::begin(); it; )
         {
Index: code/branches/gui/src/core/input/ExtendedInputState.h
===================================================================
--- code/branches/gui/src/core/input/ExtendedInputState.h	(revision 1645)
+++ code/branches/gui/src/core/input/ExtendedInputState.h	(revision 1646)
@@ -47,8 +47,8 @@
     class _CoreExport ExtendedInputState : public InputState
     {
+        friend class InputManager;
+        friend class ClassFactory<ExtendedInputState>;
+
     public:
-        ExtendedInputState();
-        ~ExtendedInputState() { }
-
         bool addKeyHandler        (KeyHandler* handler);
         bool removeKeyHandler     (KeyHandler* handler);
@@ -68,4 +68,7 @@
 
     private:
+        ExtendedInputState();
+        ~ExtendedInputState() { }
+
         void tickInput(float dt);
         void tickInput(float dt, unsigned int device);
Index: code/branches/gui/src/core/input/InputManager.cc
===================================================================
--- code/branches/gui/src/core/input/InputManager.cc	(revision 1645)
+++ code/branches/gui/src/core/input/InputManager.cc	(revision 1646)
@@ -429,6 +429,6 @@
                     (*rit).second->onLeave();
                 }
-                activeStates_.clear();
-                _updateActiveStates();
+                //activeStates_.clear();
+                //_updateActiveStates();
 
                 // destroy all input states
@@ -438,7 +438,7 @@
                 }
 
-                stateEmpty_ = 0;
-                stateCalibrator_ = 0;
-                stateDetector_ = 0;
+                //stateEmpty_ = 0;
+                //stateCalibrator_ = 0;
+                //stateDetector_ = 0;
 
                 // destroy the devices
@@ -448,8 +448,8 @@
 
                 // 0 joy sticks now
-                _redimensionLists();
+                //_redimensionLists();
 
                 OIS::InputManager::destroyInputSystem(inputSystem_);
-                inputSystem_ = 0;
+                //inputSystem_ = 0;
 
                 CCOUT(3) << "Destroying done." << std::endl;
@@ -509,4 +509,10 @@
     {
         assert(state);
+        std::map<int, InputState*>::iterator it = this->activeStates_.find(state->getPriority());
+        if (it != this->activeStates_.end())
+        {
+            this->activeStates_.erase(it);
+            _updateActiveStates();
+        }
         inputStatesByPriority_.erase(state->getPriority());
         inputStatesByName_.erase(state->getName());
Index: code/branches/gui/src/core/input/InputState.h
===================================================================
--- code/branches/gui/src/core/input/InputState.h	(revision 1645)
+++ code/branches/gui/src/core/input/InputState.h	(revision 1646)
@@ -51,8 +51,4 @@
 
     public:
-        InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0)
-        { RegisterObject(InputState); }
-        virtual ~InputState() { }
-
         const std::string& getName() const { return name_; }
         int getPriority()            const { return priority_; }
@@ -93,4 +89,8 @@
 
     protected:
+        InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0)
+        { RegisterObject(InputState); }
+        virtual ~InputState() { }
+
         virtual void numberOfJoySticksChanged(unsigned int n) = 0;
         void setInputDeviceEnabled(unsigned int device, bool bEnabled)
Index: code/branches/gui/src/core/input/SimpleInputState.h
===================================================================
--- code/branches/gui/src/core/input/SimpleInputState.h	(revision 1645)
+++ code/branches/gui/src/core/input/SimpleInputState.h	(revision 1646)
@@ -45,8 +45,8 @@
     class _CoreExport SimpleInputState : public InputState
     {
+        friend class InputManager;
+        friend class ClassFactory<SimpleInputState>;
+
     public:
-        SimpleInputState();
-        ~SimpleInputState() { }
-
         void setKeyHandler        (KeyHandler* handler) { keyHandler_ = handler; update(); }
         void setMouseHandler      (MouseHandler* handler) { mouseHandler_ = handler; update(); }
@@ -57,4 +57,7 @@
 
     private:
+        SimpleInputState();
+        ~SimpleInputState() { }
+
         void tickInput(float dt);
         void tickInput(float dt, unsigned int device);
