Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7957 for code/branches/kicklib


Ignore:
Timestamp:
Feb 24, 2011, 4:15:06 PM (14 years ago)
Author:
rgrieder
Message:

Changed destruction handling in GUIManager:
Use a ScopeGuard that gets invoked at destruction, even if the constructor didn't finish.
Now do all the destructive work in GUIManager::cleanup() instead of the d'tor (or using scoped_ptrs).

Location:
code/branches/kicklib/src/libraries/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib/src/libraries/core/GUIManager.cc

    r7941 r7957  
    112112    */
    113113    GUIManager::GUIManager(const std::pair<int, int>& mousePosition)
    114         : resourceProvider_(NULL)
     114        : destroyer_(*this, &GUIManager::cleanup)
     115        , guiRenderer_(NULL)
     116        , luaState_(NULL)
     117        , scriptModule_(NULL)
     118        , guiSystem_(NULL)
     119        , resourceProvider_(NULL)
    115120        , camera_(NULL)
    116121    {
     
    123128
    124129        // Note: No SceneManager specified yet
    125         guiRenderer_.reset(new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
     130        guiRenderer_ = new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000);
    126131        resourceProvider_ = guiRenderer_->createResourceProvider();
    127132        resourceProvider_->setDefaultResourceGroup("General");
    128133
    129134        // Setup scripting
    130         luaState_.reset(new LuaState());
     135        luaState_ = new LuaState();
    131136        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua");
    132137        // This is necessary to ensure that input events also use the right resource info when triggering lua functions
    133138        luaState_->setDefaultResourceInfo(this->rootFileInfo_);
    134         scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState()));
     139        scriptModule_ = new LuaScriptModule(luaState_->getInternalLuaState());
    135140        scriptModule_->setDefaultPCallErrorHandler(LuaState::ERROR_HANDLER_NAME);
    136141
     
    138143        std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger());
    139144        ceguiLogger->setLogFilename(PathConfig::getLogPathString() + "cegui.log");
    140         // set the log level according to ours (translate by subtracting 1)
     145        // Set the log level according to ours (translate by subtracting 1)
    141146        ceguiLogger->setLoggingLevel(
    142147            static_cast<LoggingLevel>(OutputHandler::getInstance().getSoftDebugLevel("logFile") - 1));
     
    144149
    145150        // Create the CEGUI system singleton
    146         guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
     151        guiSystem_ = new System(guiRenderer_, resourceProvider_, 0, scriptModule_);
    147152
    148153        // Align CEGUI mouse with OIS mouse
     
    169174    }
    170175
    171     /**
    172     @brief
    173         Basically shuts down CEGUI (member smart pointers) but first unloads our Tolua modules.
    174     */
    175     GUIManager::~GUIManager()
    176     {
     176    void GUIManager::cleanup()
     177    {
     178        using namespace CEGUI;
     179
     180        delete guiSystem_;
     181        delete guiRenderer_;
     182        delete scriptModule_;
     183        delete luaState_;
    177184    }
    178185
  • code/branches/kicklib/src/libraries/core/GUIManager.h

    r7874 r7957  
    4444#include <boost/scoped_ptr.hpp>
    4545#include <boost/shared_ptr.hpp>
     46#include <loki/ScopeGuard.h>
    4647
    4748#include "util/OgreForwardRefs.h"
     
    7778    public:
    7879        GUIManager(const std::pair<int, int>& mousePosition);
    79         ~GUIManager();
     80        //! Leave empty and use cleanup() instead
     81        ~GUIManager() {}
    8082
    8183        void setConfigValues(void);
     
    9597        const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
    9698        LuaState* getLuaState(void)
    97             { return this->luaState_.get(); }
     99            { return this->luaState_; }
    98100
    99101        //! Returns the root window for all menu sheets
     
    118120    private:
    119121        GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
     122
     123        /// Destructor that also executes when object fails to construct
     124        void cleanup();
     125
    120126        void executeCode(const std::string& str);
    121127
     
    138144        virtual void windowFocusChanged(bool bFocus);
    139145
    140         scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;      //!< CEGUI's interface to the Ogre Engine
    141         scoped_ptr<LuaState>                 luaState_;         //!< LuaState, access point to the Lua engine
    142         scoped_ptr<CEGUI::LuaScriptModule>   scriptModule_;     //!< CEGUI's script module to use Lua
    143         scoped_ptr<CEGUI::System>            guiSystem_;        //!< CEGUI's main system
     146        /// Surrogate for the destructor
     147        Loki::ObjScopeGuardImpl0<GUIManager, void (GUIManager::*)()> destroyer_;
     148
     149        CEGUI::OgreCEGUIRenderer*            guiRenderer_;      //!< CEGUI's interface to the Ogre Engine
     150        CEGUI::ResourceProvider*             resourceProvider_; //!< CEGUI's resource provider
     151        LuaState*                            luaState_;         //!< LuaState, access point to the Lua engine
     152        CEGUI::LuaScriptModule*              scriptModule_;     //!< CEGUI's script module to use Lua
     153        CEGUI::System*                       guiSystem_;        //!< CEGUI's main system
    144154        shared_ptr<ResourceInfo>             rootFileInfo_;     //!< Resource information about the root script
    145         CEGUI::ResourceProvider*             resourceProvider_; //!< CEGUI's resource provider
    146155        CEGUI::Logger*                       ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
    147156        CEGUI::Window*                       rootWindow_;       //!< Root node for all windows
Note: See TracChangeset for help on using the changeset viewer.