Index: /code/branches/resource3/src/core/Core.cc
===================================================================
--- /code/branches/resource3/src/core/Core.cc	(revision 5676)
+++ /code/branches/resource3/src/core/Core.cc	(revision 5677)
@@ -313,4 +313,7 @@
         // creates the class hierarchy for all classes with factories
         Factory::createClassHierarchy();
+
+        // Load OGRE excluding the renderer and the render window
+        this->graphicsManager_.reset(new GraphicsManager(false));
     }
 
@@ -325,23 +328,21 @@
     void Core::loadGraphics()
     {
-        if (bGraphicsLoaded_)
-            return;
-
-        // Load OGRE including the render window
-        scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager());
+        // Any exception should trigger this, even in upgradeToGraphics (see its remarks)
+        Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics);
+
+        // Upgrade OGRE to receive a render window
+        graphicsManager_->upgradeToGraphics();
 
         // The render window width and height are used to set up the mouse movement.
         size_t windowHnd = 0;
-        graphicsManager->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
+        graphicsManager_->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
 
         // Calls the InputManager which sets up the input devices.
-        scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));
+        inputManager_.reset(new InputManager(windowHnd));
 
         // load the CEGUI interface
-        guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow()));
-
-        // Dismiss scoped pointers
-        graphicsManager_.swap(graphicsManager);
-        inputManager_.swap(inputManager);
+        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow()));
+
+        unloader.Dismiss();
 
         bGraphicsLoaded_ = true;
@@ -350,10 +351,18 @@
     void Core::unloadGraphics()
     {
-        if (!bGraphicsLoaded_)
-            return;
-
         this->guiManager_.reset();;
         this->inputManager_.reset();;
         this->graphicsManager_.reset();
+
+        // Load Ogre::Root again, but without the render system
+        try
+            { this->graphicsManager_.reset(new GraphicsManager(false)); }
+        catch (...)
+        {
+            COUT(0) << "An exception occurred during 'new GraphicsManager' while "
+                    << "another exception was being handled. This will lead to undefined behaviour!" << std::endl
+                    << "Terminating the program." << std::endl;
+            abort();
+        }
 
         bGraphicsLoaded_ = false;
Index: /code/branches/resource3/src/core/Core.h
===================================================================
--- /code/branches/resource3/src/core/Core.h	(revision 5676)
+++ /code/branches/resource3/src/core/Core.h	(revision 5677)
@@ -66,4 +66,5 @@
         typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard;
         friend class Singleton<Core>;
+        friend class Game;
 
         public:
@@ -82,7 +83,4 @@
             bool preUpdate(const Clock& time) throw();
             bool postUpdate(const Clock& time) throw();
-
-            void loadGraphics();
-            void unloadGraphics();
 
             static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
@@ -113,4 +111,7 @@
         private:
             Core(const Core&); //!< Don't use (undefined symbol)
+
+            void loadGraphics();
+            void unloadGraphics();
 
             void checkDevBuild();
Index: /code/branches/resource3/src/core/GraphicsManager.cc
===================================================================
--- /code/branches/resource3/src/core/GraphicsManager.cc	(revision 5676)
+++ /code/branches/resource3/src/core/GraphicsManager.cc	(revision 5677)
@@ -37,9 +37,6 @@
 
 #include <fstream>
-#include <memory>
 #include <boost/filesystem.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include <OgreCompositorManager.h>
+
 #include <OgreConfigFile.h>
 #include <OgreFrameListener.h>
@@ -49,5 +46,4 @@
 #include <OgreRenderWindow.h>
 #include <OgreRenderSystem.h>
-#include <OgreTextureManager.h>
 #include <OgreViewport.h>
 #include <OgreWindowEventUtilities.h>
@@ -68,6 +64,4 @@
 namespace orxonox
 {
-    using boost::shared_ptr;
-
     class OgreWindowEventListener : public Ogre::WindowEventListener
     {
@@ -89,10 +83,8 @@
         Non-initialising constructor.
     */
-    GraphicsManager::GraphicsManager()
-        : ogreRoot_(0)
-        , ogreLogger_(0)
+    GraphicsManager::GraphicsManager(bool bLoadRenderer)
+        : ogreWindowEventListener_(new OgreWindowEventListener())
         , renderWindow_(0)
         , viewport_(0)
-        , ogreWindowEventListener_(new OgreWindowEventListener())
     {
         RegisterObject(GraphicsManager);
@@ -100,55 +92,21 @@
         this->setConfigValues();
 
-        // Ogre setup procedure
-        setupOgre();
-
-        try
-        {
-            // load all the required plugins for Ogre
-            loadOgrePlugins();
-            // read resource declaration file
-            this->declareResources();
-            // Reads ogre config and creates the render window
-            this->loadRenderer();
-
-            // TODO: Spread this
-            this->initialiseResources();
-
-            // add console commands
-            FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
-            functor1->setObject(this);
-            ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
-            CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
-        }
-        catch (...)
-        {
-            // clean up
-            delete this->ogreRoot_;
-            delete this->ogreLogger_;
-            delete this->ogreWindowEventListener_;
-            throw;
-        }
-    }
-
-    /**
-    @brief
-        Destroys all the Ogre related objects
+        // Ogre setup procedure (creating Ogre::Root)
+        this->loadOgreRoot();
+        // load all the required plugins for Ogre
+        this->loadOgrePlugins();
+        // read resource declaration file
+        this->declareResources();
+
+        if (bLoadRenderer)
+            this->upgradeToGraphics();
+    }
+
+    /**
+    @brief
+        Destruction is done by the member scoped_ptrs.
     */
     GraphicsManager::~GraphicsManager()
     {
-/*
-        delete this->ccPrintScreen_;
-*/
-
-        // unload all compositors (this is only necessary because we don't yet destroy all resources!)
-        Ogre::CompositorManager::getSingleton().removeAll();
-
-        // Delete OGRE main control organ
-        delete this->ogreRoot_;
-
-        // delete the logManager (since we have created it in the first place).
-        delete this->ogreLogger_;
-
-        delete this->ogreWindowEventListener_;
     }
 
@@ -173,38 +131,20 @@
     }
 
-    void GraphicsManager::update(const Clock& time)
-    {
-        Ogre::FrameEvent evt;
-        evt.timeSinceLastFrame = time.getDeltaTime();
-        evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
-
-        // don't forget to call _fireFrameStarted to OGRE to make sure
-        // everything goes smoothly
-        ogreRoot_->_fireFrameStarted(evt);
-
-        // Pump messages in all registered RenderWindows
-        // This calls the WindowEventListener objects.
-        Ogre::WindowEventUtilities::messagePump();
-        // make sure the window stays active even when not focused
-        // (probably only necessary on windows)
-        this->renderWindow_->setActive(true);
-
-        // Time before rendering
-        uint64_t timeBeforeTick = time.getRealMicroseconds();
-
-        // Render frame
-        ogreRoot_->_updateAllRenderTargets();
-
-        uint64_t timeAfterTick = time.getRealMicroseconds();
-        // Subtract the time used for rendering from the tick time counter
-        Game::getInstance().subtractTickTime(timeAfterTick - timeBeforeTick);
-
-        // again, just to be sure OGRE works fine
-        ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
-    }
-
-    void GraphicsManager::setCamera(Ogre::Camera* camera)
-    {
-        this->viewport_->setCamera(camera);
+    /**
+    @brief
+        Loads the renderer and creates the render window if not yet done so.
+    @remarks
+        This operation is irreversible without recreating the GraphicsManager!
+        So if it throws you HAVE to recreate the GraphicsManager!!!
+        It therefore offers almost no exception safety.
+    */
+    void GraphicsManager::upgradeToGraphics()
+    {
+        if (renderWindow_ == NULL)
+        {
+            // Reads the ogre config and creates the render window
+            this->loadRenderer();
+            this->initialiseResources();
+        }
     }
 
@@ -213,5 +153,5 @@
         Creates the Ogre Root object and sets up the ogre log.
     */
-    void GraphicsManager::setupOgre()
+    void GraphicsManager::loadOgreRoot()
     {
         COUT(3) << "Setting up Ogre..." << std::endl;
@@ -233,10 +173,10 @@
         // create a new logManager
         // Ogre::Root will detect that we've already created a Log
-        std::auto_ptr<Ogre::LogManager> logger(new Ogre::LogManager());
+        ogreLogger_.reset(new Ogre::LogManager());
         COUT(4) << "Ogre LogManager created" << std::endl;
 
         // create our own log that we can listen to
         Ogre::Log *myLog;
-        myLog = logger->createLog(ogreLogFilepath.string(), true, false, false);
+        myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
         COUT(4) << "Ogre Log created" << std::endl;
 
@@ -256,7 +196,5 @@
 
         // Leave plugins file empty. We're going to do that part manually later
-        ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
-        // In case that new Root failed the logger gets destroyed because of the std::auto_ptr
-        ogreLogger_ = logger.release();
+        ogreRoot_.reset(new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()));
 
         COUT(3) << "Ogre set up done." << std::endl;
@@ -340,12 +278,19 @@
 
         this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
+        // Propagate the size of the new winodw
         this->ogreWindowEventListener_->windowResized(renderWindow_);
 
-        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);
-
-        Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
+        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_.get());
 
         // create a full screen default viewport
+        // Note: This may throw when adding a viewport with an existing z-order!
+        //       But in our case we only have one viewport for now anyway, therefore
+        //       no ScopeGuards or anything to handle exceptions.
         this->viewport_ = this->renderWindow_->addViewport(0, 0);
+
+        // add console commands
+        FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen);
+        ccPrintScreen_ = createConsoleCommand(functor1->setObject(this), "printScreen");
+        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
     }
 
@@ -370,4 +315,40 @@
     }
 
+    void GraphicsManager::update(const Clock& time)
+    {
+        Ogre::FrameEvent evt;
+        evt.timeSinceLastFrame = time.getDeltaTime();
+        evt.timeSinceLastEvent = time.getDeltaTime(); // note: same time, but shouldn't matter anyway
+
+        // don't forget to call _fireFrameStarted to OGRE to make sure
+        // everything goes smoothly
+        ogreRoot_->_fireFrameStarted(evt);
+
+        // Pump messages in all registered RenderWindows
+        // This calls the WindowEventListener objects.
+        Ogre::WindowEventUtilities::messagePump();
+        // make sure the window stays active even when not focused
+        // (probably only necessary on windows)
+        this->renderWindow_->setActive(true);
+
+        // Time before rendering
+        uint64_t timeBeforeTick = time.getRealMicroseconds();
+
+        // Render frame
+        ogreRoot_->_updateAllRenderTargets();
+
+        uint64_t timeAfterTick = time.getRealMicroseconds();
+        // Subtract the time used for rendering from the tick time counter
+        Game::getInstance().subtractTickTime(timeAfterTick - timeBeforeTick);
+
+        // again, just to be sure OGRE works fine
+        ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
+    }
+
+    void GraphicsManager::setCamera(Ogre::Camera* camera)
+    {
+        this->viewport_->setCamera(camera);
+    }
+
     /**
     @brief
Index: /code/branches/resource3/src/core/GraphicsManager.h
===================================================================
--- /code/branches/resource3/src/core/GraphicsManager.h	(revision 5676)
+++ /code/branches/resource3/src/core/GraphicsManager.h	(revision 5677)
@@ -42,4 +42,6 @@
 #include <string>
 #include <OgreLog.h>
+#include <boost/scoped_ptr.hpp>
+
 #include "util/Singleton.h"
 #include "OrxonoxClass.h"
@@ -47,4 +49,6 @@
 namespace orxonox
 {
+    using boost::scoped_ptr;
+
     /**
     @brief
@@ -55,5 +59,5 @@
         friend class Singleton<GraphicsManager>;
     public:
-        GraphicsManager();
+        GraphicsManager(bool bLoadRenderer = true);
         ~GraphicsManager();
 
@@ -62,8 +66,9 @@
         void update(const Clock& time);
 
-        inline Ogre::Viewport* getViewport()
-            { return this->viewport_; }
-        inline Ogre::RenderWindow* getRenderWindow()
-            { return this->renderWindow_; }
+        Ogre::Viewport* getViewport()         { return this->viewport_; }
+        Ogre::RenderWindow* getRenderWindow() { return this->renderWindow_; }
+
+        void upgradeToGraphics();
+        bool rendererLoaded() const { return renderWindow_ != NULL; }
 
         void setCamera(Ogre::Camera* camera);
@@ -73,5 +78,5 @@
 
         // OGRE initialisation
-        void setupOgre();
+        void loadOgreRoot();
         void loadOgrePlugins();
         void declareResources();
@@ -87,9 +92,9 @@
 
     private:
-        Ogre::Root*         ogreRoot_;                 //!< Ogre's root
-        Ogre::LogManager*   ogreLogger_;
+        scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
+        scoped_ptr<Ogre::LogManager>        ogreLogger_;
+        scoped_ptr<Ogre::Root>              ogreRoot_;                //!< Ogre's root
         Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
         Ogre::Viewport*     viewport_;                 //!< default full size viewport
-        OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
 
         // config values
Index: /code/branches/resource3/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- /code/branches/resource3/src/orxonox/gamestates/GSLevel.cc	(revision 5676)
+++ /code/branches/resource3/src/orxonox/gamestates/GSLevel.cc	(revision 5677)
@@ -29,4 +29,6 @@
 
 #include "GSLevel.h"
+
+#include <OgreCompositorManager.h>
 
 #include "core/input/InputManager.h"
@@ -170,4 +172,9 @@
 */
 
+        if (GameMode::showsGraphics())
+        {
+            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
+            Ogre::CompositorManager::getSingleton().removeAll();
+        }
 
         // this call will delete every BaseObject!
