Index: /code/branches/kicklib/src/libraries/core/GUIManager.cc
===================================================================
--- /code/branches/kicklib/src/libraries/core/GUIManager.cc	(revision 7956)
+++ /code/branches/kicklib/src/libraries/core/GUIManager.cc	(revision 7957)
@@ -112,5 +112,10 @@
     */
     GUIManager::GUIManager(const std::pair<int, int>& mousePosition)
-        : resourceProvider_(NULL)
+        : destroyer_(*this, &GUIManager::cleanup)
+        , guiRenderer_(NULL)
+        , luaState_(NULL)
+        , scriptModule_(NULL)
+        , guiSystem_(NULL)
+        , resourceProvider_(NULL)
         , camera_(NULL)
     {
@@ -123,14 +128,14 @@
 
         // Note: No SceneManager specified yet
-        guiRenderer_.reset(new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
+        guiRenderer_ = new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000);
         resourceProvider_ = guiRenderer_->createResourceProvider();
         resourceProvider_->setDefaultResourceGroup("General");
 
         // Setup scripting
-        luaState_.reset(new LuaState());
+        luaState_ = new LuaState();
         rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua");
         // This is necessary to ensure that input events also use the right resource info when triggering lua functions
         luaState_->setDefaultResourceInfo(this->rootFileInfo_);
-        scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState()));
+        scriptModule_ = new LuaScriptModule(luaState_->getInternalLuaState());
         scriptModule_->setDefaultPCallErrorHandler(LuaState::ERROR_HANDLER_NAME);
 
@@ -138,5 +143,5 @@
         std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger());
         ceguiLogger->setLogFilename(PathConfig::getLogPathString() + "cegui.log");
-        // set the log level according to ours (translate by subtracting 1)
+        // Set the log level according to ours (translate by subtracting 1)
         ceguiLogger->setLoggingLevel(
             static_cast<LoggingLevel>(OutputHandler::getInstance().getSoftDebugLevel("logFile") - 1));
@@ -144,5 +149,5 @@
 
         // Create the CEGUI system singleton
-        guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
+        guiSystem_ = new System(guiRenderer_, resourceProvider_, 0, scriptModule_);
 
         // Align CEGUI mouse with OIS mouse
@@ -169,10 +174,12 @@
     }
 
-    /**
-    @brief
-        Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules.
-    */
-    GUIManager::~GUIManager()
-    {
+    void GUIManager::cleanup()
+    {
+        using namespace CEGUI;
+
+        delete guiSystem_;
+        delete guiRenderer_;
+        delete scriptModule_;
+        delete luaState_;
     }
 
Index: /code/branches/kicklib/src/libraries/core/GUIManager.h
===================================================================
--- /code/branches/kicklib/src/libraries/core/GUIManager.h	(revision 7956)
+++ /code/branches/kicklib/src/libraries/core/GUIManager.h	(revision 7957)
@@ -44,4 +44,5 @@
 #include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
+#include <loki/ScopeGuard.h>
 
 #include "util/OgreForwardRefs.h"
@@ -77,5 +78,6 @@
     public:
         GUIManager(const std::pair<int, int>& mousePosition);
-        ~GUIManager();
+        //! Leave empty and use cleanup() instead
+        ~GUIManager() {}
 
         void setConfigValues(void);
@@ -95,5 +97,5 @@
         const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
         LuaState* getLuaState(void)
-            { return this->luaState_.get(); }
+            { return this->luaState_; }
 
         //! Returns the root window for all menu sheets
@@ -118,4 +120,8 @@
     private:
         GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
+
+        /// Destructor that also executes when object fails to construct
+        void cleanup();
+
         void executeCode(const std::string& str);
 
@@ -138,10 +144,13 @@
         virtual void windowFocusChanged(bool bFocus);
 
-        scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;      //!< CEGUI's interface to the Ogre Engine
-        scoped_ptr<LuaState>                 luaState_;         //!< LuaState, access point to the Lua engine
-        scoped_ptr<CEGUI::LuaScriptModule>   scriptModule_;     //!< CEGUI's script module to use Lua
-        scoped_ptr<CEGUI::System>            guiSystem_;        //!< CEGUI's main system
+        /// Surrogate for the destructor
+        Loki::ObjScopeGuardImpl0<GUIManager, void (GUIManager::*)()> destroyer_;
+
+        CEGUI::OgreCEGUIRenderer*            guiRenderer_;      //!< CEGUI's interface to the Ogre Engine
+        CEGUI::ResourceProvider*             resourceProvider_; //!< CEGUI's resource provider
+        LuaState*                            luaState_;         //!< LuaState, access point to the Lua engine
+        CEGUI::LuaScriptModule*              scriptModule_;     //!< CEGUI's script module to use Lua
+        CEGUI::System*                       guiSystem_;        //!< CEGUI's main system
         shared_ptr<ResourceInfo>             rootFileInfo_;     //!< Resource information about the root script
-        CEGUI::ResourceProvider*             resourceProvider_; //!< CEGUI's resource provider
         CEGUI::Logger*                       ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
         CEGUI::Window*                       rootWindow_;       //!< Root node for all windows
