Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 9, 2011, 5:06:49 AM (14 years ago)
Author:
rgrieder
Message:

Added and incorporated new class DestructionHelper: instead of doing the destruction of certain singletons implicitly via scoped_ptrs and ScopeGuards, use a method named destroy() that essentially achieves the same, but makes the destruction sequence obvious.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/Core.cc

    r8366 r8423  
    9090
    9191    Core::Core(const std::string& cmdLine)
    92         // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
    93         : identifierDestroyer_(Identifier::destroyAllIdentifiers)
    94         // Cleanup guard for external console commands that don't belong to an Identifier
    95         , consoleCommandDestroyer_(ConsoleCommand::destroyAll)
     92        : pathConfig_(NULL)
     93        , dynLibManager_(NULL)
     94        , signalHandler_(NULL)
     95        , configFileManager_(NULL)
     96        , languageInstance_(NULL)
     97        , ioConsole_(NULL)
     98        , tclBind_(NULL)
     99        , tclThreadManager_(NULL)
     100        , rootScope_(NULL)
     101        , graphicsManager_(NULL)
     102        , inputManager_(NULL)
     103        , guiManager_(NULL)
     104        , graphicsScope_(NULL)
    96105        , bGraphicsLoaded_(false)
    97106        , bStartIOConsole_(true)
     
    99108        , ogreConfigTimestamp_(0)
    100109        , bDevMode_(false)
     110        , destructionHelper_(this)
    101111    {
    102112        // Set the hard coded fixed paths
    103         this->pathConfig_.reset(new PathConfig());
     113        this->pathConfig_ = new PathConfig();
    104114
    105115        // Create a new dynamic library manager
    106         this->dynLibManager_.reset(new DynLibManager());
     116        this->dynLibManager_ = new DynLibManager();
    107117
    108118        // Load modules
     
    128138        // create a signal handler (only active for Linux)
    129139        // This call is placed as soon as possible, but after the directories are set
    130         this->signalHandler_.reset(new SignalHandler());
     140        this->signalHandler_ = new SignalHandler();
    131141        this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log");
    132142
     
    147157
    148158        // Manage ini files and set the default settings file (usually orxonox.ini)
    149         this->configFileManager_.reset(new ConfigFileManager());
     159        this->configFileManager_ = new ConfigFileManager();
    150160        this->configFileManager_->setFilename(ConfigFileType::Settings,
    151161            CommandLineParser::getValue("settingsFile").getString());
    152162
    153163        // Required as well for the config values
    154         this->languageInstance_.reset(new Language());
     164        this->languageInstance_ = new Language();
    155165
    156166        // Do this soon after the ConfigFileManager has been created to open up the
    157167        // possibility to configure everything below here
    158         ClassIdentifier<Core>::getIdentifier("Core")->initialiseObject(this, "Core", true);
     168        RegisterRootObject(Core);
    159169        this->setConfigValues();
    160170
     
    166176        }
    167177        if (this->bStartIOConsole_)
    168             this->ioConsole_.reset(new IOConsole());
     178            this->ioConsole_ = new IOConsole();
    169179#endif
    170180
     
    173183
    174184        // Load OGRE excluding the renderer and the render window
    175         this->graphicsManager_.reset(new GraphicsManager(false));
     185        this->graphicsManager_ = new GraphicsManager(false);
    176186
    177187        // initialise Tcl
    178         this->tclBind_.reset(new TclBind(PathConfig::getDataPathString()));
    179         this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
     188        this->tclBind_ = new TclBind(PathConfig::getDataPathString());
     189        this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
    180190
    181191        // Create singletons that always exist (in other libraries)
    182         this->rootScope_.reset(new Scope<ScopeID::Root>());
     192        this->rootScope_ = new Scope<ScopeID::Root>();
    183193
    184194        // Generate documentation instead of normal run?
     
    198208    }
    199209
    200     /**
    201     @brief
    202         All destruction code is handled by scoped_ptrs and ScopeGuards.
    203     */
    204     Core::~Core()
     210    void Core::destroy()
    205211    {
    206212        // Remove us from the object lists again to avoid problems when destroying them
    207213        this->unregisterObject();
     214
     215        safeObjectDelete(&graphicsScope_);
     216        safeObjectDelete(&guiManager_);
     217        safeObjectDelete(&inputManager_);
     218        safeObjectDelete(&graphicsManager_);
     219        safeObjectDelete(&rootScope_);
     220        safeObjectDelete(&tclThreadManager_);
     221        safeObjectDelete(&tclBind_);
     222        safeObjectDelete(&ioConsole_);
     223        safeObjectDelete(&languageInstance_);
     224        safeObjectDelete(&configFileManager_);
     225        ConsoleCommand::destroyAll();
     226        Identifier::destroyAllIdentifiers();
     227        safeObjectDelete(&signalHandler_);
     228        safeObjectDelete(&dynLibManager_);
     229        safeObjectDelete(&pathConfig_);
    208230    }
    209231
     
    285307
    286308        // Calls the InputManager which sets up the input devices.
    287         inputManager_.reset(new InputManager());
     309        inputManager_ = new InputManager();
    288310
    289311        // Load the CEGUI interface
    290         guiManager_.reset(new GUIManager(inputManager_->getMousePosition()));
     312        guiManager_ = new GUIManager(inputManager_->getMousePosition());
    291313
    292314        bGraphicsLoaded_ = true;
     
    297319
    298320        // Create singletons associated with graphics (in other libraries)
    299         graphicsScope_.reset(new Scope<ScopeID::Graphics>());
     321        graphicsScope_ = new Scope<ScopeID::Graphics>();
    300322
    301323        unloader.Dismiss();
     
    304326    void Core::unloadGraphics()
    305327    {
    306         this->graphicsScope_.reset();
    307         this->guiManager_.reset();
    308         this->inputManager_.reset();
    309         this->graphicsManager_.reset();
     328        safeObjectDelete(&graphicsScope_);
     329        safeObjectDelete(&guiManager_);
     330        safeObjectDelete(&inputManager_);
     331        safeObjectDelete(&graphicsManager_);
    310332
    311333        // Load Ogre::Root again, but without the render system
    312334        try
    313             { this->graphicsManager_.reset(new GraphicsManager(false)); }
     335            { this->graphicsManager_ = new GraphicsManager(false); }
    314336        catch (...)
    315337        {
Note: See TracChangeset for help on using the changeset viewer.