[Orxonox-commit 3266] r7957 - code/branches/kicklib/src/libraries/core
rgrieder at orxonox.net
rgrieder at orxonox.net
Thu Feb 24 16:15:06 CET 2011
Author: rgrieder
Date: 2011-02-24 16:15:06 +0100 (Thu, 24 Feb 2011)
New Revision: 7957
Modified:
code/branches/kicklib/src/libraries/core/GUIManager.cc
code/branches/kicklib/src/libraries/core/GUIManager.h
Log:
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).
Modified: code/branches/kicklib/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/kicklib/src/libraries/core/GUIManager.cc 2011-02-24 06:40:07 UTC (rev 7956)
+++ code/branches/kicklib/src/libraries/core/GUIManager.cc 2011-02-24 15:15:06 UTC (rev 7957)
@@ -111,7 +111,12 @@
@return true if success, otherwise false
*/
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)
{
RegisterRootObject(GUIManager);
@@ -122,28 +127,28 @@
COUT(3) << "Initialising CEGUI." << std::endl;
// 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);
// Create our own logger to specify the filepath
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));
this->ceguiLogger_ = ceguiLogger.release();
// 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
guiSystem_->injectMousePosition((float)mousePosition.first, (float)mousePosition.second);
@@ -168,12 +173,14 @@
this->luaState_->doFile("SheetManager.lua");
}
- /**
- @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_;
}
void GUIManager::setConfigValues(void)
Modified: code/branches/kicklib/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/kicklib/src/libraries/core/GUIManager.h 2011-02-24 06:40:07 UTC (rev 7956)
+++ code/branches/kicklib/src/libraries/core/GUIManager.h 2011-02-24 15:15:06 UTC (rev 7957)
@@ -43,6 +43,7 @@
#include <CEGUIForwardRefs.h>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
+#include <loki/ScopeGuard.h>
#include "util/OgreForwardRefs.h"
#include "util/TriBool.h"
@@ -76,7 +77,8 @@
friend class Singleton<GUIManager>;
public:
GUIManager(const std::pair<int, int>& mousePosition);
- ~GUIManager();
+ //! Leave empty and use cleanup() instead
+ ~GUIManager() {}
void setConfigValues(void);
void changedGUIScheme(void);
@@ -94,7 +96,7 @@
//! Creates a new InputState to be used with a GUI Sheet
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
CEGUI::Window* getMenuRootWindow() { return this->menuRootWindow_; } // tolua_export
@@ -117,6 +119,10 @@
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);
template <typename FunctionType>
@@ -137,12 +143,15 @@
virtual void windowResized(unsigned int newWidth, unsigned int newHeight);
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
CEGUI::Window* hudRootWindow_; //!< Root node for the HUD sheets
More information about the Orxonox-commit
mailing list