Index: code/branches/resource/src/orxonox/gui/GUIManager.cc
===================================================================
--- code/branches/resource/src/orxonox/gui/GUIManager.cc	(revision 3337)
+++ code/branches/resource/src/orxonox/gui/GUIManager.cc	(revision 3338)
@@ -36,4 +36,5 @@
 #include "GUIManager.h"
 
+#include <memory>
 extern "C" {
 #include <lua.h>
@@ -89,51 +90,7 @@
     GUIManager* GUIManager::singletonRef_s = 0;
 
-    GUIManager::GUIManager()
-        : renderWindow_(0)
-        , guiRenderer_(0)
-        , resourceProvider_(0)
-        , scriptModule_(0)
-        , guiSystem_(0)
-        , state_(Uninitialised)
-    {
-        assert(singletonRef_s == 0);
-        singletonRef_s = this;
-    }
-
-    /**
-    @brief
-        Deconstructor of the GUIManager
-
-        Basically shuts down CEGUI and destroys the Lua engine and afterwards the interface to the Ogre engine.
-    */
-    GUIManager::~GUIManager()
-    {
-        if (guiSystem_)
-            delete guiSystem_;
-
-        if (scriptModule_)
-        {
-            // destroy our own tolua interfaces
-            lua_pushnil(luaState_);
-            lua_setglobal(luaState_, "Orxonox");
-            lua_pushnil(luaState_);
-            lua_setglobal(luaState_, "Core");
-            delete scriptModule_;
-        }
-
-        if (guiRenderer_)
-            delete guiRenderer_;
-
-        singletonRef_s = 0;
-    }
-
-    /**
-    @brief
-        Initialises the GUIManager by starting up CEGUI
-    @param renderWindow
-        Ogre's render window. Without this, the GUI cannot be displayed.
-    @return true if success, otherwise false
-
-        Before this call the GUIManager won't do anything, but can be accessed.
+    /**
+    @brief
+        Constructs the GUIManager by starting up CEGUI
 
         Creates the interface to Ogre, sets up the CEGUI renderer and the Lua script module together with the Lua engine.
@@ -141,57 +98,74 @@
         After Lua setup tolua++-elements are linked to Lua-state to give Lua access to C++-code.
         Finally initial Lua code is executed (maybe we can do this with the CEGUI startup script automatically).
-    */
-    bool GUIManager::initialise(Ogre::RenderWindow* renderWindow)
-    {
+    @param renderWindow
+        Ogre's render window. Without this, the GUI cannot be displayed.
+    @return true if success, otherwise false
+    */
+    GUIManager::GUIManager(Ogre::RenderWindow* renderWindow)
+        : renderWindow_(renderWindow)
+        , resourceProvider_(0)
+    {
+        assert(singletonRef_s == 0);
+        singletonRef_s = this;
+
         using namespace CEGUI;
-        if (state_ == Uninitialised)
-        {
-            COUT(3) << "Initialising CEGUI." << std::endl;
-
-            try
-            {
-                // save the render window
-                renderWindow_ = renderWindow;
-
-                // Note: No SceneManager specified yet
-                this->guiRenderer_ = new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, false, 3000);
-                this->resourceProvider_ = guiRenderer_->createResourceProvider();
-                this->resourceProvider_->setDefaultResourceGroup("GUI");
-
-                // setup scripting
-                this->scriptModule_ = new LuaScriptModule();
-                this->luaState_ = this->scriptModule_->getLuaState();
-
-                // Create our own logger to specify the filepath
-                this->ceguiLogger_ = new CEGUILogger();
-                this->ceguiLogger_->setLogFilename(Core::getLogPathString() + "cegui.log");
-                // set the log level according to ours (translate by subtracting 1)
-                this->ceguiLogger_->setLoggingLevel(
-                    (LoggingLevel)(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1));
-
-                // create the CEGUI system singleton
-                this->guiSystem_ = new System(this->guiRenderer_, this->resourceProvider_, 0, this->scriptModule_);
-
-                // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place
-                tolua_Core_open(this->scriptModule_->getLuaState());
-                tolua_Orxonox_open(this->scriptModule_->getLuaState());
-
-                // initialise the basic lua code
-                loadLuaCode();
-            }
-            catch (CEGUI::Exception& ex)
-            {
+
+        COUT(3) << "Initialising CEGUI." << std::endl;
+
+        try
+        {
+            // Note: No SceneManager specified yet
+            guiRenderer_.reset(new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
+            resourceProvider_ = guiRenderer_->createResourceProvider();
+            resourceProvider_->setDefaultResourceGroup("GUI");
+
+            // setup scripting
+            scriptModule_.reset(new LuaScriptModule());
+            luaState_ = scriptModule_->getLuaState();
+
+            // Create our own logger to specify the filepath
+            std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger());
+            ceguiLogger->setLogFilename(Core::getLogPathString() + "cegui.log");
+            // set the log level according to ours (translate by subtracting 1)
+            ceguiLogger->setLoggingLevel(
+                static_cast<LoggingLevel>(Core::getSoftDebugLevel(OutputHandler::LD_Logfile) - 1));
+            this->ceguiLogger_ = ceguiLogger.release();
+
+            // create the CEGUI system singleton
+            guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
+
+            // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place
+            tolua_Core_open(this->scriptModule_->getLuaState());
+            tolua_Orxonox_open(this->scriptModule_->getLuaState());
+
+            // initialise the basic lua code
+            this->loadLuaCode();
+        }
+        catch (CEGUI::Exception& ex)
+        {
 #if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6
-                throw GeneralException(ex.getMessage().c_str());
+            throw GeneralException(ex.getMessage().c_str());
 #else
-                throw GeneralException(ex.getMessage().c_str(), ex.getLine(),
-                    ex.getFileName().c_str(), ex.getName().c_str());
+            throw GeneralException(ex.getMessage().c_str(), ex.getLine(),
+                ex.getFileName().c_str(), ex.getName().c_str());
 #endif
-            }
-
-            state_ = Ready;
-        }
-
-        return true;
+        }
+    }
+
+    /**
+    @brief
+        Destructor of the GUIManager
+
+        Basically shuts down CEGUI and destroys the Lua engine and afterwards the interface to the Ogre engine.
+    */
+    GUIManager::~GUIManager()
+    {
+        // destroy our own tolua interfaces
+        lua_pushnil(luaState_);
+        lua_setglobal(luaState_, "Orxonox");
+        lua_pushnil(luaState_);
+        lua_setglobal(luaState_, "Core");
+
+        singletonRef_s = 0;
     }
 
@@ -245,24 +219,4 @@
 
     /**
-    @brief
-        Executes Lua code
-    @param str
-        reference to string object holding the Lua code which is to be executed
-
-        This function gives total access to the GUI. You can execute ANY Lua code here.
-    */
-    void GUIManager::executeCode(const std::string& str)
-    {
-        try
-        {
-            this->scriptModule_->executeString(str);
-        }
-        catch (CEGUI::Exception& ex)
-        {
-            COUT(2) << "CEGUI Error: \"" << ex.getMessage() << "\" while executing code \"" << str << "\"" << std::endl;
-        }
-    }
-
-    /**
 
     */
@@ -305,4 +259,28 @@
     /**
     @brief
+        Executes Lua code
+    @param str
+        reference to string object holding the Lua code which is to be executed
+
+        This function gives total access to the GUI. You can execute ANY Lua code here.
+    */
+    void GUIManager::executeCode(const std::string& str)
+    {
+        try
+        {
+            this->scriptModule_->executeString(str);
+        }
+        catch (const CEGUI::Exception& ex)
+        {
+            COUT(2) << "CEGUI Error: \"" << ex.getMessage() << "\" while executing code \"" << str << "\"" << std::endl;
+        }
+        catch (...)
+        {
+            COUT(2) << "Couldn't execute GUI related Lua code due to unknown reasons." << std::endl;
+        }
+    }
+
+    /**
+    @brief
         Displays specified GUI on screen
     @param name
@@ -314,24 +292,5 @@
     void GUIManager::showGUI(const std::string& name)
     {
-        if (state_ != Uninitialised)
-        {
-            //COUT(3) << "Loading GUI " << name << std::endl;
-            try
-            {
-                this->scriptModule_->executeString(std::string("showGUI(\"") + name + "\")");
-            }
-            catch (CEGUI::Exception& ex)
-            {
-                COUT(2) << "Error while executing lua script. Message:\n" << ex.getMessage() << std::endl;
-            }
-            catch (...)
-            {
-                COUT(2) << "Could show a menu due to unknown reasons." << std::endl;
-            }
-        }
-        else
-        {
-            COUT(2) << "Warning: GUI Manager not yet initialised, cannot load a GUI" << std::endl;
-        }
+        this->executeCode(std::string("showGUI(\"") + name + "\")");
     }
 
Index: code/branches/resource/src/orxonox/gui/GUIManager.h
===================================================================
--- code/branches/resource/src/orxonox/gui/GUIManager.h	(revision 3337)
+++ code/branches/resource/src/orxonox/gui/GUIManager.h	(revision 3338)
@@ -42,4 +42,5 @@
 #include <string>
 #include <CEGUIForwardRefs.h>
+#include <boost/scoped_ptr.hpp>
 
 #include "util/OgreForwardRefs.h"
@@ -67,19 +68,6 @@
 // tolua_end
     public:
-        /**
-        @enum State
-            The current state of the GUIManager. There should maybe be more (or we can omit this totally).
-        */
-        enum State
-        {
-            Uninitialised,  //!< Initial state of the GUIManager
-            Ready,          //!< State after initialisation if ready
-            OnDisplay       //!< State if GUI is displayed
-        };
-
-        GUIManager();
+        GUIManager(Ogre::RenderWindow* renderWindow);
         ~GUIManager();
-
-        bool initialise(Ogre::RenderWindow* renderWindow);
 
         void update(const Clock& time);
@@ -110,15 +98,13 @@
         void mouseScrolled (int abs, int rel);
 
-        Ogre::RenderWindow*         renderWindow_;      //!< Ogre's render window to give CEGUI access to it
-        CEGUI::OgreCEGUIRenderer*   guiRenderer_;       //!< CEGUI's interface to the Ogre Engine
-        CEGUI::ResourceProvider*    resourceProvider_;  //!< CEGUI's resource provider
-        CEGUI::LuaScriptModule*     scriptModule_;      //!< CEGUI's script module to use Lua
-        CEGUI::Logger*              ceguiLogger_;       //!< CEGUI's logger to be able to log CEGUI errors in our log
-        CEGUI::System*              guiSystem_;         //!< CEGUI's main system
-        lua_State*                  luaState_;          //!< Lua state, access point to the Lua engine
+        boost::scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;  //!< CEGUI's interface to the Ogre Engine
+        boost::scoped_ptr<CEGUI::LuaScriptModule>   scriptModule_; //!< CEGUI's script module to use Lua
+        boost::scoped_ptr<CEGUI::System>            guiSystem_;    //!< CEGUI's main system
+        Ogre::RenderWindow*      renderWindow_;     //!< Ogre's render window to give CEGUI access to it
+        CEGUI::ResourceProvider* resourceProvider_; //!< CEGUI's resource provider
+        CEGUI::Logger*           ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
+        lua_State*               luaState_;         //!< Lua state, access point to the Lua engine
 
-        State                       state_;             //!< reflects state of the GUIManager
-
-        static GUIManager*          singletonRef_s;     //!< Singleton reference to GUIManager
+        static GUIManager*       singletonRef_s;    //!< Singleton reference to GUIManager
 
     }; // tolua_export
