Index: code/trunk/src/libraries/core/Core.cc
===================================================================
--- code/trunk/src/libraries/core/Core.cc	(revision 8419)
+++ code/trunk/src/libraries/core/Core.cc	(revision 8423)
@@ -90,8 +90,17 @@
 
     Core::Core(const std::string& cmdLine)
-        // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
-        : identifierDestroyer_(Identifier::destroyAllIdentifiers)
-        // Cleanup guard for external console commands that don't belong to an Identifier
-        , consoleCommandDestroyer_(ConsoleCommand::destroyAll)
+        : pathConfig_(NULL)
+        , dynLibManager_(NULL)
+        , signalHandler_(NULL)
+        , configFileManager_(NULL)
+        , languageInstance_(NULL)
+        , ioConsole_(NULL)
+        , tclBind_(NULL)
+        , tclThreadManager_(NULL)
+        , rootScope_(NULL)
+        , graphicsManager_(NULL)
+        , inputManager_(NULL)
+        , guiManager_(NULL)
+        , graphicsScope_(NULL)
         , bGraphicsLoaded_(false)
         , bStartIOConsole_(true)
@@ -99,10 +108,11 @@
         , ogreConfigTimestamp_(0)
         , bDevMode_(false)
+        , destructionHelper_(this)
     {
         // Set the hard coded fixed paths
-        this->pathConfig_.reset(new PathConfig());
+        this->pathConfig_ = new PathConfig();
 
         // Create a new dynamic library manager
-        this->dynLibManager_.reset(new DynLibManager());
+        this->dynLibManager_ = new DynLibManager();
 
         // Load modules
@@ -128,5 +138,5 @@
         // create a signal handler (only active for Linux)
         // This call is placed as soon as possible, but after the directories are set
-        this->signalHandler_.reset(new SignalHandler());
+        this->signalHandler_ = new SignalHandler();
         this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log");
 
@@ -147,14 +157,14 @@
 
         // Manage ini files and set the default settings file (usually orxonox.ini)
-        this->configFileManager_.reset(new ConfigFileManager());
+        this->configFileManager_ = new ConfigFileManager();
         this->configFileManager_->setFilename(ConfigFileType::Settings,
             CommandLineParser::getValue("settingsFile").getString());
 
         // Required as well for the config values
-        this->languageInstance_.reset(new Language());
+        this->languageInstance_ = new Language();
 
         // Do this soon after the ConfigFileManager has been created to open up the
         // possibility to configure everything below here
-        ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true);
+        RegisterRootObject(Core);
         this->setConfigValues();
 
@@ -166,5 +176,5 @@
         }
         if (this->bStartIOConsole_)
-            this->ioConsole_.reset(new IOConsole());
+            this->ioConsole_ = new IOConsole();
 #endif
 
@@ -173,12 +183,12 @@
 
         // Load OGRE excluding the renderer and the render window
-        this->graphicsManager_.reset(new GraphicsManager(false));
+        this->graphicsManager_ = new GraphicsManager(false);
 
         // initialise Tcl
-        this->tclBind_.reset(new TclBind(PathConfig::getDataPathString()));
-        this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
+        this->tclBind_ = new TclBind(PathConfig::getDataPathString());
+        this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
 
         // Create singletons that always exist (in other libraries)
-        this->rootScope_.reset(new Scope<ScopeID::Root>());
+        this->rootScope_ = new Scope<ScopeID::Root>();
 
         // Generate documentation instead of normal run?
@@ -198,12 +208,24 @@
     }
 
-    /**
-    @brief
-        All destruction code is handled by scoped_ptrs and ScopeGuards.
-    */
-    Core::~Core()
+    void Core::destroy()
     {
         // Remove us from the object lists again to avoid problems when destroying them
         this->unregisterObject();
+
+        safeObjectDelete(&graphicsScope_);
+        safeObjectDelete(&guiManager_);
+        safeObjectDelete(&inputManager_);
+        safeObjectDelete(&graphicsManager_);
+        safeObjectDelete(&rootScope_);
+        safeObjectDelete(&tclThreadManager_);
+        safeObjectDelete(&tclBind_);
+        safeObjectDelete(&ioConsole_);
+        safeObjectDelete(&languageInstance_);
+        safeObjectDelete(&configFileManager_);
+        ConsoleCommand::destroyAll();
+        Identifier::destroyAllIdentifiers();
+        safeObjectDelete(&signalHandler_);
+        safeObjectDelete(&dynLibManager_);
+        safeObjectDelete(&pathConfig_);
     }
 
@@ -285,8 +307,8 @@
 
         // Calls the InputManager which sets up the input devices.
-        inputManager_.reset(new InputManager());
+        inputManager_ = new InputManager();
 
         // Load the CEGUI interface
-        guiManager_.reset(new GUIManager(inputManager_->getMousePosition()));
+        guiManager_ = new GUIManager(inputManager_->getMousePosition());
 
         bGraphicsLoaded_ = true;
@@ -297,5 +319,5 @@
 
         // Create singletons associated with graphics (in other libraries)
-        graphicsScope_.reset(new Scope<ScopeID::Graphics>());
+        graphicsScope_ = new Scope<ScopeID::Graphics>();
 
         unloader.Dismiss();
@@ -304,12 +326,12 @@
     void Core::unloadGraphics()
     {
-        this->graphicsScope_.reset();
-        this->guiManager_.reset();
-        this->inputManager_.reset();
-        this->graphicsManager_.reset();
+        safeObjectDelete(&graphicsScope_);
+        safeObjectDelete(&guiManager_);
+        safeObjectDelete(&inputManager_);
+        safeObjectDelete(&graphicsManager_);
 
         // Load Ogre::Root again, but without the render system
         try
-            { this->graphicsManager_.reset(new GraphicsManager(false)); }
+            { this->graphicsManager_ = new GraphicsManager(false); }
         catch (...)
         {
Index: code/trunk/src/libraries/core/Core.h
===================================================================
--- code/trunk/src/libraries/core/Core.h	(revision 8419)
+++ code/trunk/src/libraries/core/Core.h	(revision 8423)
@@ -45,7 +45,7 @@
 
 #include <string>
-#include <boost/scoped_ptr.hpp>
 #include <loki/ScopeGuard.h>
 
+#include "util/DestructionHelper.h"
 #include "util/Singleton.h"
 #include "OrxonoxClass.h"
@@ -61,5 +61,4 @@
     class _CoreExport Core : public Singleton<Core>, public OrxonoxClass
     {
-        typedef Loki::ScopeGuardImpl0<void (*)()> SimpleScopeGuard;
         friend class Singleton<Core>;
         friend class Game;
@@ -74,5 +73,9 @@
             */
             Core(const std::string& cmdLine);
-            ~Core();
+
+            /// Leave empty and use destroy() instead
+            ~Core() {}
+            /// Destructor that also executes when the object fails to construct
+            void destroy();
 
             void setConfigValues();
@@ -108,33 +111,33 @@
 
             void setThreadAffinity(int limitToCPU);
-            // MANAGED SINGLETONS/OBJECTS
-            // Mind the order for the destruction!
-            scoped_ptr<PathConfig>        pathConfig_;
-            scoped_ptr<DynLibManager>     dynLibManager_;
-            scoped_ptr<SignalHandler>     signalHandler_;
-            SimpleScopeGuard              identifierDestroyer_;
-            SimpleScopeGuard              consoleCommandDestroyer_;
-            scoped_ptr<ConfigFileManager> configFileManager_;
-            scoped_ptr<Language>          languageInstance_;
-            scoped_ptr<IOConsole>         ioConsole_;
-            scoped_ptr<TclBind>           tclBind_;
-            scoped_ptr<TclThreadManager>  tclThreadManager_;
-            scoped_ptr<Scope<ScopeID::Root> > rootScope_;
+
+            PathConfig*               pathConfig_;
+            DynLibManager*            dynLibManager_;
+            SignalHandler*            signalHandler_;
+            ConfigFileManager*        configFileManager_;
+            Language*                 languageInstance_;
+            IOConsole*                ioConsole_;
+            TclBind*                  tclBind_;
+            TclThreadManager*         tclThreadManager_;
+            Scope<ScopeID::Root>*     rootScope_;
             // graphical
-            scoped_ptr<GraphicsManager>   graphicsManager_;     //!< Interface to OGRE
-            scoped_ptr<InputManager>      inputManager_;        //!< Interface to OIS
-            scoped_ptr<GUIManager>        guiManager_;          //!< Interface to GUI
-            scoped_ptr<Scope<ScopeID::Graphics> > graphicsScope_;
+            GraphicsManager*          graphicsManager_;            //!< Interface to OGRE
+            InputManager*             inputManager_;               //!< Interface to OIS
+            GUIManager*               guiManager_;                 //!< Interface to GUI
+            Scope<ScopeID::Graphics>* graphicsScope_;
 
-            bool                          bGraphicsLoaded_;
-            int                           softDebugLevelLogFile_;      //!< The debug level for the log file (belongs to OutputHandler)
-            std::string                   language_;                   //!< The language
-            bool                          bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
-            bool                          bStartIOConsole_;            //!< Set to false if you don't want to use the IOConsole
-            long long                     lastLevelTimestamp_;         ///< Timestamp when the last level was started
-            long long                     ogreConfigTimestamp_;        ///< Timestamp wehen the ogre config level was modified
-            bool                          bDevMode_;                   //!< Developers bit. If set to false, some options are not available as to not confuse the normal user.
+            bool                      bGraphicsLoaded_;
+            int                       softDebugLevelLogFile_;      //!< The debug level for the log file (belongs to OutputHandler)
+            std::string               language_;                   //!< The language
+            bool                      bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
+            bool                      bStartIOConsole_;            //!< Set to false if you don't want to use the IOConsole
+            long long                 lastLevelTimestamp_;         ///< Timestamp when the last level was started
+            long long                 ogreConfigTimestamp_;        ///< Timestamp wehen the ogre config level was modified
+            bool                      bDevMode_;                   //!< Developers bit. If set to false, some options are not available as to not confuse the normal user.
 
-            static Core*                  singletonPtr_s;
+            /// Helper object that executes the surrogate destructor destroy()
+            DestructionHelper<Core>   destructionHelper_;
+
+            static Core*              singletonPtr_s;
     };
 }
Index: code/trunk/src/libraries/core/GUIManager.cc
===================================================================
--- code/trunk/src/libraries/core/GUIManager.cc	(revision 8419)
+++ code/trunk/src/libraries/core/GUIManager.cc	(revision 8423)
@@ -162,6 +162,5 @@
     */
     GUIManager::GUIManager(const std::pair<int, int>& mousePosition)
-        : destroyer_(*this, &GUIManager::cleanup)
-        , guiRenderer_(NULL)
+        : guiRenderer_(NULL)
         , resourceProvider_(NULL)
 #ifndef ORXONOX_OLD_CEGUI
@@ -177,4 +176,5 @@
         , menuRootWindow_(NULL)
         , camera_(NULL)
+        , destructionHelper_(this)
     {
         RegisterRootObject(GUIManager);
@@ -258,12 +258,12 @@
     }
 
-    void GUIManager::cleanup()
+    void GUIManager::destroy()
     {
         using namespace CEGUI;
 
 #ifdef ORXONOX_OLD_CEGUI
-        delete guiSystem_;
-        delete guiRenderer_;
-        delete scriptModule_;
+        safeObjectDelete(&guiSystem_);
+        safeObjectDelete(&guiRenderer_);
+        safeObjectDelete(&scriptModule_);
 #else
         System::destroy();
@@ -272,8 +272,8 @@
         OgreRenderer::destroy(*guiRenderer_);
         LuaScriptModule::destroy(*scriptModule_);
-        delete ceguiLogger_;
-        delete rqListener_;
-#endif
-        delete luaState_;
+        safeObjectDelete(&ceguiLogger_);
+        safeObjectDelete(&rqListener_);
+#endif
+        safeObjectDelete(&luaState_);
     }
 
@@ -285,5 +285,4 @@
     void GUIManager::changedGUIScheme(void)
     {
-
     }
 
Index: code/trunk/src/libraries/core/GUIManager.h
===================================================================
--- code/trunk/src/libraries/core/GUIManager.h	(revision 8419)
+++ code/trunk/src/libraries/core/GUIManager.h	(revision 8423)
@@ -44,6 +44,6 @@
 #include <CEGUIVersion.h>
 #include <boost/shared_ptr.hpp>
-#include <loki/ScopeGuard.h>
 
+#include "util/DestructionHelper.h"
 #include "util/OgreForwardRefs.h"
 #include "util/TriBool.h"
@@ -83,6 +83,9 @@
     public:
         GUIManager(const std::pair<int, int>& mousePosition);
+
         //! Leave empty and use cleanup() instead
         ~GUIManager() {}
+        /// Destructor that also executes when object fails to construct
+        void destroy();
 
         void setConfigValues(void);
@@ -134,7 +137,4 @@
         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);
 
@@ -156,7 +156,4 @@
         virtual void windowResized(unsigned int newWidth, unsigned int newHeight);
         virtual void windowFocusChanged(bool bFocus);
-
-        /// Surrogate for the destructor
-        Loki::ObjScopeGuardImpl0<GUIManager, void (GUIManager::*)()> destroyer_;
 
 #ifdef ORXONOX_OLD_CEGUI
@@ -180,4 +177,7 @@
         Ogre::Camera*                        camera_;           //!< Camera used to render the scene with the GUI
 
+        /// Helper object that executes the surrogate destructor destroy()
+        DestructionHelper<GUIManager>        destructionHelper_;
+
         static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
 
Index: code/trunk/src/libraries/core/Game.cc
===================================================================
--- code/trunk/src/libraries/core/Game.cc	(revision 8419)
+++ code/trunk/src/libraries/core/Game.cc	(revision 8423)
@@ -78,10 +78,10 @@
 
     Game::Game(const std::string& cmdLine)
-        // Destroy factories before the Core!
-        : gsFactoryDestroyer_(Game::GameStateFactory::getFactories(), &std::map<std::string, shared_ptr<GameStateFactory> >::clear)
-    {
-        this->bAbort_ = false;
-        bChangingState_ = false;
-
+        : gameClock_(NULL)
+        , core_(NULL)
+        , bChangingState_(false)
+        , bAbort_(false)
+        , destructionHelper_(this)
+    {
 #ifdef ORXONOX_PLATFORM_WINDOWS
         minimumSleepTime_ = 1000/*us*/;
@@ -103,8 +103,8 @@
 
         // Set up a basic clock to keep time
-        this->gameClock_.reset(new Clock());
+        this->gameClock_ = new Clock();
 
         // Create the Core
-        this->core_.reset(new Core(cmdLine));
+        this->core_ = new Core(cmdLine);
 
         // Do this after the Core creation!
@@ -127,12 +127,16 @@
     }
 
-    /**
-    @brief
-        All destruction code is handled by scoped_ptrs and SimpleScopeGuards.
-    */
-    Game::~Game()
+    void Game::destroy()
     {
         // Remove us from the object lists again to avoid problems when destroying them
         this->unregisterObject();
+
+        assert(loadedStates_.size() <= 1); // Just empty root GameState
+        // Destroy all GameStates (shared_ptrs take care of actual destruction)
+        constructedStates_.clear();
+
+        GameStateFactory::getFactories().clear();
+        safeObjectDelete(&core_);
+        safeObjectDelete(&gameClock_);
     }
 
Index: code/trunk/src/libraries/core/Game.h
===================================================================
--- code/trunk/src/libraries/core/Game.h	(revision 8419)
+++ code/trunk/src/libraries/core/Game.h	(revision 8423)
@@ -45,9 +45,8 @@
 #include <vector>
 #include <boost/shared_ptr.hpp>
-#include <boost/scoped_ptr.hpp>
 #include <boost/preprocessor/cat.hpp>
-#include <loki/ScopeGuard.h>
 
 #include "util/Debug.h"
+#include "util/DestructionHelper.h"
 #include "util/Singleton.h"
 #include "OrxonoxClass.h"
@@ -56,5 +55,5 @@
 @brief
     Adds a new GameState to the Game. The second parameter is the name as string
-    and every following paramter is a constructor argument (which is usually non existent)
+    and every following parameter is a constructor argument (which is usually non existent)
 */
 #define DeclareGameState(className, stateName, bIgnoreTickTime, bGraphicsMode) \
@@ -92,5 +91,9 @@
     public:
         Game(const std::string& cmdLine);
-        ~Game();
+
+        //! Leave empty and use cleanup() instead
+        ~Game() {}
+        /// Destructor that also executes when object fails to construct
+        void destroy();
 
         void setConfigValues();
@@ -138,6 +141,4 @@
                 { return shared_ptr<GameState>(new T(info)); }
         };
-        // For the factory destruction
-        typedef Loki::ObjScopeGuardImpl0<std::map<std::string, shared_ptr<GameStateFactory> >, void (std::map<std::string, shared_ptr<GameStateFactory> >::*)()> ObjScopeGuard;
 
         struct StatisticsTickInfo
@@ -166,7 +167,6 @@
         void resetChangingState() { this->bChangingState_ = false; }
 
-        scoped_ptr<Clock>                  gameClock_;
-        scoped_ptr<Core>                   core_;
-        ObjScopeGuard                      gsFactoryDestroyer_;
+        Clock*                             gameClock_;
+        Core*                              core_;
 
         GameStateMap                       constructedStates_;
@@ -194,4 +194,7 @@
         unsigned int                       fpsLimit_;
 
+        /// Helper object that executes the surrogate destructor destroy()
+        DestructionHelper<Game>            destructionHelper_;
+
         static std::map<std::string, GameStateInfo> gameStateDeclarations_s;
         static Game* singletonPtr_s;        //!< Pointer to the Singleton
Index: code/trunk/src/libraries/core/GraphicsManager.cc
===================================================================
--- code/trunk/src/libraries/core/GraphicsManager.cc	(revision 8419)
+++ code/trunk/src/libraries/core/GraphicsManager.cc	(revision 8423)
@@ -94,8 +94,4 @@
     GraphicsManager* GraphicsManager::singletonPtr_s = 0;
 
-    /**
-    @brief
-        Non-initialising constructor.
-    */
     GraphicsManager::GraphicsManager(bool bLoadRenderer)
         : ogreWindowEventListener_(new OgreWindowEventListener())
@@ -104,4 +100,5 @@
         , lastFrameStartTime_(0.0f)
         , lastFrameEndTime_(0.0f)
+        , destructionHelper_(this)
     {
         RegisterObject(GraphicsManager);
@@ -134,13 +131,9 @@
     }
 
-    /**
-    @brief
-        Destruction is done by the member scoped_ptrs.
-    */
-    GraphicsManager::~GraphicsManager()
+    void GraphicsManager::destroy()
     {
         Loader::unload(debugOverlay_.get());
 
-        Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get());
+        Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_);
         ModifyConsoleCommand(__CC_printScreen_name).resetFunction();
         ModifyConsoleCommand(__CC_GraphicsManager_group, __CC_setScreenResolution_name).resetFunction();
@@ -151,4 +144,8 @@
         Loader::unload(resources_.get());
         Loader::unload(extResources_.get());
+
+        safeObjectDelete(&ogreRoot_);
+        safeObjectDelete(&ogreLogger_);
+        safeObjectDelete(&ogreWindowEventListener_);
     }
 
@@ -218,5 +215,5 @@
         // create a new logManager
         // Ogre::Root will detect that we've already created a Log
-        ogreLogger_.reset(new Ogre::LogManager());
+        ogreLogger_ = new Ogre::LogManager();
         COUT(4) << "Ogre LogManager created" << std::endl;
 
@@ -241,5 +238,5 @@
 
         // Leave plugins file empty. We're going to do that part manually later
-        ogreRoot_.reset(new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string()));
+        ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
 
         COUT(3) << "Ogre set up done." << std::endl;
@@ -300,5 +297,5 @@
         this->ogreWindowEventListener_->windowResized(renderWindow_);
 
-        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_.get());
+        Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, ogreWindowEventListener_);
 
         // create a full screen default viewport
Index: code/trunk/src/libraries/core/GraphicsManager.h
===================================================================
--- code/trunk/src/libraries/core/GraphicsManager.h	(revision 8419)
+++ code/trunk/src/libraries/core/GraphicsManager.h	(revision 8423)
@@ -48,7 +48,7 @@
 #include <string>
 #include <OgreLog.h>
-#include <boost/scoped_ptr.hpp>
 #include <boost/shared_ptr.hpp>
 
+#include "util/DestructionHelper.h"
 #include "util/Singleton.h"
 #include "OrxonoxClass.h"
@@ -68,5 +68,9 @@
     public:
         GraphicsManager(bool bLoadRenderer = true);
-        ~GraphicsManager();
+
+        //! Leave empty and use cleanup() instead
+        ~GraphicsManager() {}
+        /// Destructor that also executes when object fails to construct
+        void destroy();
 
         void setConfigValues();
@@ -113,7 +117,7 @@
         std::string setVSync(bool vsync);
 
-        scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
-        scoped_ptr<Ogre::LogManager>        ogreLogger_;
-        scoped_ptr<Ogre::Root>              ogreRoot_;                //!< Ogre's root
+        OgreWindowEventListener* ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
+        Ogre::LogManager*        ogreLogger_;
+        Ogre::Root*              ogreRoot_;                //!< Ogre's root
         Ogre::RenderWindow* renderWindow_;             //!< the one and only render window
         Ogre::Viewport*     viewport_;                 //!< default full size viewport
@@ -134,4 +138,7 @@
         int                 ogreLogLevelCritical_;     //!< Corresponding Orxonox debug level for LL_CRITICAL
 
+        /// Helper object that executes the surrogate destructor destroy()
+        DestructionHelper<GraphicsManager> destructionHelper_;
+
         static GraphicsManager* singletonPtr_s;        //!< Pointer to the Singleton
 // tolua_begin
