Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 4, 2008, 8:28:14 PM (16 years ago)
Author:
rgrieder
Message:

Completed destruction of static elements like XMLPort, Identifier, etc.
Of initially about 250 memory leaks (not in the actual meaning but the memory was never freed anyway) only 1 remains in TinyCpp.

  • Core class is now a normal Singleton that gets created and destroyed in main.
  • The same goes for Language, LuaBind, SignalHandler and PlayerManager.
  • Added a new std::set to the CommandExecutor so that the external ConsoleCommands can get destroyed too.
  • Code for destroying CommandLineArguments
  • Added destruction code for ConstructionCallbacks in Identifier
  • Moved internal identifier map (the one with the typeid(.) names) in a static function in Identifier. This was necessary in order to destroy ALL Identifiers with the static destruction function. Before it was possible to create an Identifier with having a class instance (that would call RegisterObject) for instance by simply accessing it via getIdentifier.
  • Removed a big memory leak in Button (forgot to destroy the ConfigValueContainers)
  • Added destruction code for InputBufferListenerTuples in InputBuffer destructor.
  • Added destruction code for load and save executors in both XMLPortParam and XMLPortObject
  • Added destruction code for ConsoleCommands in GSRoot, GSGraphics and GSLevel (temporary solution anyway)
  • Deleting the CEGUILua script module seems to work properly now, one memory leak less (GUIManager.cc)
  • Added global destruction calls in Main.cc
Location:
code/branches/objecthierarchy2/src
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy2/src/core/CommandExecutor.cc

    r1784 r2344  
    5353    }
    5454
    55     ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command)
     55    ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit)
    5656    {
    5757        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName());
     
    6161        }
    6262
     63        // Make sure we can also delete the external ConsoleCommands that don't belong to an Identifier
     64        if (command && bDeleteAtExit)
     65        {
     66            CommandExecutor::getInstance().consoleCommandExternals_.insert(command);
     67        }
    6368
    6469        CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command;
     
    647652        }
    648653    }
     654
     655    void CommandExecutor::destroyExternalCommands()
     656    {
     657        for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin();
     658            it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it)
     659            delete *it;
     660    }
    649661}
  • code/branches/objecthierarchy2/src/core/CommandExecutor.h

    r1771 r2344  
    5151            static const CommandEvaluation& getLastEvaluation();
    5252
    53             static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command);
     53            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false);
    5454            static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
    5555            static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
     
    6868            /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    6969            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
     70
     71            static void destroyExternalCommands();
    7072
    7173        private:
     
    101103            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
    102104            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
     105            std::set<ConsoleCommand*>              consoleCommandExternals_;
    103106    }; // tolua_export
    104107} // tolua_export
  • code/branches/objecthierarchy2/src/core/CommandLine.cc

    r2105 r2344  
    8383    CommandLine::~CommandLine()
    8484    {
    85         for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();
    86             it != cmdLineArgs_.end(); ++it)
    87         {
    88             delete it->second;
    89         }
     85        CommandLine::destroyAllArguments();
    9086    }
    9187
     
    9894        static CommandLine instance;
    9995        return instance;
     96    }
     97
     98    /**
     99    @brief
     100        Destroys all command line arguments. This should be called at the end
     101        of main. Do not use before that.
     102    */
     103    void CommandLine::destroyAllArguments()
     104    {
     105        for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin();
     106            it != _getInstance().cmdLineArgs_.end(); ++it)
     107            delete it->second;
     108        _getInstance().cmdLineArgs_.clear();
    100109    }
    101110
  • code/branches/objecthierarchy2/src/core/CommandLine.h

    r2103 r2344  
    155155        }
    156156
     157        static void destroyAllArguments();
    157158
    158159    private:
     
    179180        //! Holds all pointers to the arguments and serves as a search map by name.
    180181        std::map<std::string, CommandLineArgument*> cmdLineArgs_;
    181         //! Search map by chortcut for the arguments.
     182        //! Search map by shortcut for the arguments.
    182183        std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_;
    183184    };
  • code/branches/objecthierarchy2/src/core/ConsoleCommand.h

    r2087 r2344  
    6464
    6565#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
    66     orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command)
     66    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)
    6767
    6868
  • code/branches/objecthierarchy2/src/core/Core.cc

    r2171 r2344  
    4646    bool Core::bIsMaster_s      = false;
    4747
     48    Core* Core::singletonRef_s = 0;
     49
    4850    /**
    4951        @brief Constructor: Registers the object and sets the config-values.
     
    5355    {
    5456        RegisterRootObject(Core);
     57
     58        assert(singletonRef_s == 0);
     59        singletonRef_s = this;
     60
    5561        this->setConfigValues();
    56         isCreatingCoreSettings() = false;
    5762    }
    5863
     
    6267    Core::~Core()
    6368    {
    64         isCreatingCoreSettings() = true;
    65     }
    66 
    67     /**
    68         @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value.
    69     */
    70     bool& Core::isCreatingCoreSettings()
    71     {
    72         static bool bCreatingCoreSettings = true;
    73         return bCreatingCoreSettings;
    74     }
    75 
    76     /**
    77         @brief Returns a unique instance of Core.
    78         @return The instance
    79     */
    80     Core& Core::getInstance()
    81     {
    82         // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
    83         //if (Core::isCreatingCoreSettings())
    84         //{
    85         //    isCreatingCoreSettings() = false;
    86         //    //instance.setConfigValues();
    87         //}
    88 
    89         static bool firstTime = true;
    90         if (firstTime)
    91             isCreatingCoreSettings() = true;
    92 
    93         static Core instance;
    94         return instance;
     69        assert(singletonRef_s);
     70        singletonRef_s = 0;
    9571    }
    9672
     
    140116    int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)
    141117    {
    142         if (!Core::isCreatingCoreSettings())
     118        switch (device)
    143119        {
    144             switch (device)
    145             {
    146             case OutputHandler::LD_All:
    147                 return Core::getInstance().softDebugLevel_;
    148             case OutputHandler::LD_Console:
    149                 return Core::getInstance().softDebugLevelConsole_;
    150             case OutputHandler::LD_Logfile:
    151                 return Core::getInstance().softDebugLevelLogfile_;
    152             case OutputHandler::LD_Shell:
    153                 return Core::getInstance().softDebugLevelShell_;
    154             default:
    155                 assert(0);
    156             }
     120        case OutputHandler::LD_All:
     121            return Core::getInstance().softDebugLevel_;
     122        case OutputHandler::LD_Console:
     123            return Core::getInstance().softDebugLevelConsole_;
     124        case OutputHandler::LD_Logfile:
     125            return Core::getInstance().softDebugLevelLogfile_;
     126        case OutputHandler::LD_Shell:
     127            return Core::getInstance().softDebugLevelShell_;
     128        default:
     129            assert(0);
     130            return 2;
    157131        }
    158 
    159         // Return a constant value while we're creating the object
    160         return 2;
    161132    }
    162133
     
    168139     void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
    169140     {
    170         if (!Core::isCreatingCoreSettings())
    171         {
    172             if (device == OutputHandler::LD_All)
    173                 Core::getInstance().softDebugLevel_ = level;
    174             else if (device == OutputHandler::LD_Console)
    175                 Core::getInstance().softDebugLevelConsole_ = level;
    176             else if (device == OutputHandler::LD_Logfile)
    177                 Core::getInstance().softDebugLevelLogfile_ = level;
    178             else if (device == OutputHandler::LD_Shell)
    179                 Core::getInstance().softDebugLevelShell_ = level;
     141        if (device == OutputHandler::LD_All)
     142            Core::getInstance().softDebugLevel_ = level;
     143        else if (device == OutputHandler::LD_Console)
     144            Core::getInstance().softDebugLevelConsole_ = level;
     145        else if (device == OutputHandler::LD_Logfile)
     146            Core::getInstance().softDebugLevelLogfile_ = level;
     147        else if (device == OutputHandler::LD_Shell)
     148            Core::getInstance().softDebugLevelShell_ = level;
    180149
    181             OutputHandler::setSoftDebugLevel(device, level);
    182         }
     150        OutputHandler::setSoftDebugLevel(device, level);
    183151     }
    184152
     
    188156    const std::string& Core::getLanguage()
    189157    {
    190         if (!Core::isCreatingCoreSettings())
    191             return Core::getInstance().language_;
    192 
    193         return Language::getLanguage().defaultLanguage_;
     158        return Core::getInstance().language_;
    194159    }
    195160
  • code/branches/objecthierarchy2/src/core/Core.h

    r2171 r2344  
    4040#include "CorePrereqs.h"
    4141
     42#include <cassert>
    4243#include "OrxonoxClass.h"
    4344#include "util/OutputHandler.h"
     
    4950    {
    5051        public:
    51             static Core& getInstance();
    52             static bool& isCreatingCoreSettings();
     52            Core();
     53            ~Core();
    5354            void setConfigValues();
    5455            void debugLevelChanged();
    5556            void languageChanged();
    5657
    57             static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
    58             static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
     58            static Core& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
     59
     60            static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
     61            static void  setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
    5962            static const std::string& getLanguage();
    60             static void resetLanguage();
     63            static void  resetLanguage();
    6164
    6265            // fast access global variables.
     
    7376
    7477        private:
     78            Core(const Core&);
    7579            void resetLanguageIntern();
    76 
    77             Core();
    78             Core(const Core& other);
    79             virtual ~Core();
    8080
    8181            int softDebugLevel_;                            //!< The debug level
     
    9090            static bool bIsStandalone_s;
    9191            static bool bIsMaster_s;
     92
     93            static Core* singletonRef_s;
    9294    };
    9395}
  • code/branches/objecthierarchy2/src/core/CorePrereqs.h

    r2173 r2344  
    133133  class LanguageEntry;
    134134  class Loader;
     135  class LuaBind;
    135136  class MetaObjectList;
    136137  class MetaObjectListElement;
  • code/branches/objecthierarchy2/src/core/Identifier.cc

    r2171 r2344  
    9393        for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)
    9494            delete (it->second);
     95        for (std::vector<Functor*>::iterator it = this->constructionCallbacks_.begin(); it != this->constructionCallbacks_.end(); ++it)
     96            delete *it;
     97    }
     98
     99    /**
     100        @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
     101    */
     102    std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap()
     103    {
     104        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
     105        return identifiers;
    95106    }
    96107
     
    103114    Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
    104115    {
    105         static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
    106         std::map<std::string, Identifier*>::const_iterator it = identifiers.find(name);
    107 
    108         if (it != identifiers.end())
     116        std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
     117
     118        if (it != getTypeIDIdentifierMap().end())
    109119        {
    110120            // There is already an entry: return it and delete the proposal
     
    115125        {
    116126            // There is no entry: put the proposal into the map and return it
    117             identifiers[name] = proposal;
     127            getTypeIDIdentifierMap()[name] = proposal;
    118128            return proposal;
    119129        }
     
    192202    void Identifier::destroyAllIdentifiers()
    193203    {
    194         for (std::map<std::string, Identifier*>::iterator it = Identifier::getIdentifierMapIntern().begin(); it != Identifier::getIdentifierMapIntern().end(); ++it)
     204        for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it)
    195205            delete (it->second);
    196206    }
  • code/branches/objecthierarchy2/src/core/Identifier.h

    r2171 r2344  
    257257            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
    258258
     259            static void destroyAllIdentifiers();
     260
    259261        protected:
    260262            Identifier();
     
    299301            }
    300302
     303            static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
     304
    301305            void initialize(std::set<const Identifier*>* parents);
    302 
    303             static void destroyAllIdentifiers();
    304306
    305307            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
  • code/branches/objecthierarchy2/src/core/Language.cc

    r2171 r2344  
    8787    // ###        Language         ###
    8888    // ###############################
     89
     90    Language* Language::singletonRef_s = 0;
     91
    8992    /**
    9093        @brief Constructor: Reads the default language file and sets some values.
     
    9295    Language::Language()
    9396    {
     97        assert(singletonRef_s == 0);
     98        singletonRef_s = this;
     99
    94100        this->defaultLanguage_ = "default";
    95101        this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
     
    106112        for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
    107113            delete (it->second);
    108     }
    109 
    110     /**
    111         @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function.
    112         @return The reference to the only existing instance
    113     */
    114     Language& Language::getLanguage()
    115     {
    116         static Language instance = Language();
    117         return instance;
     114
     115        assert(singletonRef_s);
     116        singletonRef_s = 0;
    118117    }
    119118
  • code/branches/objecthierarchy2/src/core/Language.h

    r2171 r2344  
    5050#include <map>
    5151#include <string>
     52#include <cassert>
    5253
    5354#define AddLanguageEntry(label, fallbackstring) \
     
    116117
    117118        public:
    118             static Language& getLanguage();
     119            Language();
     120            ~Language();
     121
     122            static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; }
    119123            void addEntry(const LanguageEntryLabel& label, const std::string& entry);
    120124            const std::string& getLocalisation(const LanguageEntryLabel& label) const;
    121125
    122126        private:
    123             Language();
    124             Language(const Language& language);     // don't copy
    125             virtual ~Language();
     127            Language(const Language&);
    126128
    127129            void readDefaultLanguageFile();
     
    134136            std::string defaultLocalisation_;                       //!< The returned string, if an entry unavailable entry is requested
    135137            std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels
     138
     139            static Language* singletonRef_s;
    136140    };
    137141}
  • code/branches/objecthierarchy2/src/core/Loader.cc

    r2171 r2344  
    120120
    121121        // let Lua work this out:
    122         LuaBind* lua = LuaBind::getInstance();
    123         lua->clearLuaOutput();
    124         lua->loadFile(file->getFilename(), true);
    125         lua->run();
     122        LuaBind& lua = LuaBind::getInstance();
     123        lua.clearLuaOutput();
     124        lua.loadFile(file->getFilename(), true);
     125        lua.run();
    126126
    127127        try
     
    135135            ticpp::Document xmlfile;
    136136            //xmlfile.ToDocument();
    137             xmlfile.Parse(lua->getLuaOutput(), true);
     137            xmlfile.Parse(lua.getLuaOutput(), true);
    138138
    139139            ticpp::Element rootElement;
  • code/branches/objecthierarchy2/src/core/LuaBind.cc

    r2087 r2344  
    4040namespace orxonox
    4141{
    42   LuaBind* LuaBind::singletonRef = NULL;
     42  LuaBind* LuaBind::singletonRef_s = NULL;
    4343
    4444  LuaBind::LuaBind()
    4545  {
     46    assert(LuaBind::singletonRef_s == 0);
     47    LuaBind::singletonRef_s = this;
     48
    4649    luaState_ = lua_open();
    4750    luaSource_ = "";
  • code/branches/objecthierarchy2/src/core/LuaBind.h

    r2087 r2344  
    4242}
    4343
     44#include <cassert>
    4445#include <list>
    4546#include <string>
     
    5859
    5960    public:
    60       inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export
    61       inline ~LuaBind() { LuaBind::singletonRef = NULL; };
     61      LuaBind();
     62      inline ~LuaBind() { assert(singletonRef_s); LuaBind::singletonRef_s = NULL; };
     63
     64      inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export
    6265
    6366    void loadFile(std::string filename, bool luaTags);
     
    8386
    8487    private:
    85       LuaBind();
    86       static LuaBind* singletonRef;
     88      static LuaBind* singletonRef_s;
    8789
    8890      std::string luaSource_;
  • code/branches/objecthierarchy2/src/core/RootGameState.cc

    r2103 r2344  
    3131#include "util/Debug.h"
    3232#include "util/Exception.h"
    33 #include "Core.h"
    3433#include "Clock.h"
    3534#include "CommandLine.h"
     
    137136            Clock clock;
    138137
    139             // create the Core settings to configure the output level
    140             Core::getInstance();
    141 
    142138            this->activate();
    143139
  • code/branches/objecthierarchy2/src/core/RootGameState.h

    r2103 r2344  
    4848        void gotoState(const std::string& name);
    4949
    50         std::string           stateRequest_;
     50        std::string stateRequest_;
    5151    };
    5252}
  • code/branches/objecthierarchy2/src/core/XMLPort.h

    r2173 r2344  
    4343#include "CorePrereqs.h"
    4444
     45#include <cassert>
    4546#include "util/Debug.h"
    4647#include "util/Exception.h"
     
    327328                this->loadexecutor_ = loadexecutor;
    328329                this->saveexecutor_ = saveexecutor;
     330            }
     331
     332            ~XMLPortClassParamContainer()
     333            {
     334                assert(this->loadexecutor_);
     335                delete this->loadexecutor_;
     336                if (this->saveexecutor_)
     337                    delete this->saveexecutor_;
    329338            }
    330339
     
    471480                this->bApplyLoaderMask_ = bApplyLoaderMask;
    472481                this->bLoadBefore_ = bLoadBefore;
     482            }
     483
     484            ~XMLPortClassObjectContainer()
     485            {
     486                assert(this->loadexecutor_);
     487                delete this->loadexecutor_;
     488                if (this->saveexecutor_)
     489                    delete this->saveexecutor_;
    473490            }
    474491
  • code/branches/objecthierarchy2/src/core/input/Button.cc

    r2103 r2344  
    5959        nCommands_[1]=0;
    6060        nCommands_[2]=0;
     61        this->configContainer_ = 0;
    6162        clear();
    6263    }
     
    8081            }
    8182        }
     83
     84        if (this->configContainer_)
     85            delete this->configContainer_;
     86        this->configContainer_ = 0;
    8287    }
    8388
  • code/branches/objecthierarchy2/src/core/input/InputBuffer.cc

    r1755 r2344  
    7373    }
    7474
     75    InputBuffer::~InputBuffer()
     76    {
     77        for (std::list<BaseInputBufferListenerTuple*>::const_iterator it = this->listeners_.begin();
     78            it != this->listeners_.end(); ++it)
     79            delete *it;
     80    }
     81
    7582    void InputBuffer::setConfigValues()
    7683    {
  • code/branches/objecthierarchy2/src/core/input/InputBuffer.h

    r1887 r2344  
    7979        public:
    8080            InputBuffer();
     81            ~InputBuffer();
    8182            InputBuffer(const std::string allowedChars);
    8283
  • code/branches/objecthierarchy2/src/orxonox/LevelManager.cc

    r2173 r2344  
    4242        assert(singletonRef_s == 0);
    4343        singletonRef_s = this;
    44 
    45         PlayerManager::getInstance(); // ensure existence of PlayerManager
    4644    }
    4745
  • code/branches/objecthierarchy2/src/orxonox/Main.cc

    r2103 r2344  
    4343#include "core/ConfigFileManager.h"
    4444#include "core/CommandLine.h"
     45#include "core/CommandExecutor.h"
     46#include "core/Identifier.h"
     47#include "core/Core.h"
     48#include "core/Language.h"
    4549
    4650#include "gamestates/GSRoot.h"
     
    9296
    9397    // create a signal handler (only works for linux)
    94     SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
     98    SignalHandler signalHandler;
     99    signalHandler.doCatch(argv[0], "orxonox.log");
    95100
    96101    // Parse command line arguments
     
    109114    ConfigFileManager* configFileManager = new ConfigFileManager();
    110115    configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString());
     116    // create the Core settings to configure the output level
     117    Language* language = new Language();
     118    Core*     core     = new Core();
    111119
    112     // create the gamestates
    113     GSRoot root;
    114     GSGraphics graphics;
    115     GSStandalone standalone;
    116     GSServer server;
    117     GSClient client;
    118     GSDedicated dedicated;
    119     GSGUI gui;
    120     GSIOConsole ioConsole;
     120    // put GameStates in its own scope so we can destroy the identifiers at the end of main().
     121    {
     122        // create the gamestates
     123        GSRoot root;
     124        GSGraphics graphics;
     125        GSStandalone standalone;
     126        GSServer server;
     127        GSClient client;
     128        GSDedicated dedicated;
     129        GSGUI gui;
     130        GSIOConsole ioConsole;
    121131
    122     // make the hierarchy
    123     root.addChild(&graphics);
    124     graphics.addChild(&standalone);
    125     graphics.addChild(&server);
    126     graphics.addChild(&client);
    127     graphics.addChild(&gui);
    128     root.addChild(&ioConsole);
    129     root.addChild(&dedicated);
     132        // make the hierarchy
     133        root.addChild(&graphics);
     134        graphics.addChild(&standalone);
     135        graphics.addChild(&server);
     136        graphics.addChild(&client);
     137        graphics.addChild(&gui);
     138        root.addChild(&ioConsole);
     139        root.addChild(&dedicated);
    130140
    131     // Here happens the game
    132     root.start();
     141        // Here happens the game
     142        root.start();
     143    }
    133144
    134     // Destroy ConfigFileManager again.
     145    // destroy singletons
     146    delete core;
     147    delete language;
    135148    delete configFileManager;
     149
     150    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
     151    Identifier::destroyAllIdentifiers();
     152    // destroy command line arguments
     153    CommandLine::destroyAllArguments();
     154    // Also delete external console command that don't belong to an Identifier
     155    CommandExecutor::destroyExternalCommands();
    136156
    137157    return 0;
  • code/branches/objecthierarchy2/src/orxonox/PlayerManager.cc

    r2171 r2344  
    3838namespace orxonox
    3939{
     40    PlayerManager* PlayerManager::singletonRef_s = 0;
     41
    4042    PlayerManager::PlayerManager()
    4143    {
    4244        RegisterRootObject(PlayerManager);
     45
     46        assert(singletonRef_s == 0);
     47        singletonRef_s = this;
    4348
    4449        this->getConnectedClients();
     
    4752    PlayerManager::~PlayerManager()
    4853    {
    49     }
    50 
    51     PlayerManager& PlayerManager::getInstance()
    52     {
    53         static PlayerManager instance;
    54         return instance;
     54        assert(singletonRef_s);
     55        singletonRef_s = 0;
    5556    }
    5657
  • code/branches/objecthierarchy2/src/orxonox/PlayerManager.h

    r2171 r2344  
    4343            virtual ~PlayerManager();
    4444
    45             static PlayerManager& getInstance();
     45            static PlayerManager& getInstance()
     46            { assert(singletonRef_s); return *singletonRef_s; }
    4647
    4748            PlayerInfo* getClient(unsigned int clientID) const;
     
    5455
    5556            std::map<unsigned int, PlayerInfo*> clients_;
     57
     58            static PlayerManager* singletonRef_s;
    5659    };
    5760}
  • code/branches/objecthierarchy2/src/orxonox/Settings.cc

    r2087 r2344  
    8383        }
    8484
    85         LuaBind::getInstance()->setIncludePath(this->dataPath_);
     85        LuaBind::getInstance().setIncludePath(this->dataPath_);
    8686    }
    8787
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.cc

    r2171 r2344  
    164164        FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
    165165        functor1->setObject(this);
    166         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen"));
     166        ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
     167        CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
    167168    }
    168169
     
    170171    {
    171172        using namespace Ogre;
     173
     174        delete this->ccPrintScreen_;
    172175
    173176        // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.h

    r2103 r2344  
    112112        unsigned int          detailLevelParticle_;      //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
    113113        std::string           defaultMasterKeybindings_; //!< Filename of default master keybindings.
     114
     115        // console commands
     116        ConsoleCommand*       ccPrintScreen_;
    114117    };
    115118}
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc

    r2173 r2344  
    4747#include "CameraManager.h"
    4848#include "LevelManager.h"
     49#include "PlayerManager.h"
    4950#include "Settings.h"
    5051
     
    99100            // create the global LevelManager
    100101            this->levelManager_ = new LevelManager();
     102            this->playerManager_ = new PlayerManager();
    101103
    102104            // reset game speed to normal
     
    114116            FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
    115117            functor1->setObject(this);
    116             CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
     118            ccKeybind_ = createConsoleCommand(functor1, "keybind");
     119            CommandExecutor::addConsoleCommandShortcut(ccKeybind_);
    117120            FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
    118121            functor2->setObject(this);
    119             CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
     122            ccTkeybind_ = createConsoleCommand(functor2, "tkeybind");
     123            CommandExecutor::addConsoleCommandShortcut(ccTkeybind_);
    120124            // set our console command as callback for the key detector
    121125            InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
     
    130134            FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
    131135            functor->setObject(this);
    132             CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
     136            ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor");
     137            CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
    133138        }
    134139    }
     
    136141    void GSLevel::leave()
    137142    {
     143        // destroy console commands
     144        delete this->ccKeybind_;
     145        delete this->ccSetTimeFactor_;
     146        delete this->ccTkeybind_;
     147
    138148        // this call will delete every BaseObject!
    139149        // But currently this will call methods of objects that exist no more
     
    156166        if (this->levelManager_)
    157167            delete this->levelManager_;
     168
     169        if (this->playerManager_)
     170            delete this->playerManager_;
    158171
    159172        if (Core::showsGraphics())
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h

    r2103 r2344  
    7070        CameraManager*        cameraManager_;
    7171        LevelManager*         levelManager_;
     72        PlayerManager*        playerManager_;
    7273
    7374        //##### ConfigValues #####
     
    7576        //! Filename of default keybindings.
    7677        std::string           defaultKeybindings_;
     78
     79        // console commands
     80        ConsoleCommand*       ccKeybind_;
     81        ConsoleCommand*       ccTkeybind_;
     82        ConsoleCommand*       ccSetTimeFactor_;
    7783
    7884    private:
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc

    r2171 r2344  
    4040#include "core/TclBind.h"
    4141#include "core/TclThreadManager.h"
     42#include "core/LuaBind.h"
    4243#include "tools/Timer.h"
    4344#include "objects/Tickable.h"
     
    8788        // creates the class hierarchy for all classes with factories
    8889        Factory::createClassHierarchy();
     90
     91        // Create the lua interface
     92        this->luaBind_ = new LuaBind();
    8993
    9094        // instantiate Settings class
     
    117121        FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
    118122        functor1->setObject(this);
    119         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit"));
     123        ccExit_ = createConsoleCommand(functor1, "exit");
     124        CommandExecutor::addConsoleCommandShortcut(ccExit_);
    120125
    121126        // add console commands
    122127        FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState);
    123128        functor2->setObject(this);
    124         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState"));
     129        ccSelectGameState_ = createConsoleCommand(functor2, "selectGameState");
     130        CommandExecutor::addConsoleCommandShortcut(ccSelectGameState_);
    125131    }
    126132
    127133    void GSRoot::leave()
    128134    {
    129         // TODO: remove and destroy console commands
     135        // destroy console commands
     136        delete this->ccExit_;
     137        delete this->ccSelectGameState_;
    130138
    131139        delete this->shell_;
     
    133141        delete this->tclBind_;
    134142
    135         delete settings_;
    136 
     143        delete this->settings_;
     144        delete this->luaBind_;
    137145    }
    138146
  • code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h

    r1891 r2344  
    5959        TclThreadManager*     tclThreadManager_;
    6060        Shell*                shell_;
     61        LuaBind*              luaBind_;
     62
     63        // console commands
     64        ConsoleCommand*       ccExit_;
     65        ConsoleCommand*       ccSelectGameState_;
    6166    };
    6267}
  • code/branches/objecthierarchy2/src/orxonox/gui/GUIManager.cc

    r2087 r2344  
    9696        {
    9797            // destroy our own tolua interfaces
    98                 //lua_pushnil(luaState_);
    99                 //lua_setglobal(luaState_, "Orxonox");
    100                 //lua_pushnil(luaState_);
    101                 //lua_setglobal(luaState_, "Core");
     98                lua_pushnil(luaState_);
     99                lua_setglobal(luaState_, "Orxonox");
     100                lua_pushnil(luaState_);
     101                lua_setglobal(luaState_, "Core");
    102102            // TODO: deleting the script module fails an assertation.
    103103            // However there is not much we can do about it since it occurs too when
    104104            // we don't open Core or Orxonox. Might be a CEGUI issue.
    105105            // The memory leak is not a problem anyway..
    106             //delete scriptModule_;
     106            delete scriptModule_;
    107107        }
    108108
  • code/branches/objecthierarchy2/src/orxonox/objects/Script.cc

    r2087 r2344  
    6464  void Script::execute()
    6565  {
    66     LuaBind* lua = LuaBind::getInstance();
    67     lua->loadString(this->code_);
    68     lua->run();
     66    LuaBind& lua = LuaBind::getInstance();
     67    lua.loadString(this->code_);
     68    lua.run();
    6969  }
    7070}
  • code/branches/objecthierarchy2/src/util/SignalHandler.cc

    r2171 r2344  
    3535#include "Debug.h"
    3636
    37 #include <cassert>
    3837#include <iostream>
    3938#include <cstdlib>
     
    4241namespace orxonox
    4342{
    44     SignalHandler * SignalHandler::singletonRef = NULL;
     43    SignalHandler* SignalHandler::singletonRef_s = NULL;
    4544}
    4645
     
    133132    void SignalHandler::sigHandler( int sig )
    134133    {
    135       for ( SignalCallbackList::iterator it = SignalHandler::getInstance()->callbackList.begin(); it != SignalHandler::getInstance()->callbackList.end(); it++  )
     134      for ( SignalCallbackList::iterator it = SignalHandler::getInstance().callbackList.begin(); it != SignalHandler::getInstance().callbackList.end(); it++  )
    136135      {
    137136        (*(it->cb))( it->someData );
     
    184183      if ( sigPid == 0 )
    185184      {
    186         getInstance()->dontCatch();
     185        getInstance().dontCatch();
    187186        // wait for message from parent when it has attached gdb
    188187        int someData;
     
    237236
    238237      char cmd[256];
    239       snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance()->appName.c_str(), sigPid );
     238      snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance().appName.c_str(), sigPid );
    240239      write( gdbIn[1], cmd, strlen(cmd) );
    241240
     
    331330      bt.insert(0, timeString);
    332331
    333       FILE * f = fopen( getInstance()->filename.c_str(), "a" );
     332      FILE * f = fopen( getInstance().filename.c_str(), "a" );
    334333
    335334      if ( !f )
    336335      {
    337         perror( ( std::string( "could not append to " ) + getInstance()->filename ).c_str() );
     336        perror( ( std::string( "could not append to " ) + getInstance().filename ).c_str() );
    338337        exit(EXIT_FAILURE);
    339338      }
     
    341340      if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() )
    342341      {
    343         COUT(0) << "could not write " << bt.length() << " byte to " << getInstance()->filename << std::endl;
     342        COUT(0) << "could not write " << bt.length() << " byte to " << getInstance().filename << std::endl;
    344343        exit(EXIT_FAILURE);
    345344      }
  • code/branches/objecthierarchy2/src/util/SignalHandler.h

    r2171 r2344  
    3737#include "UtilPrereqs.h"
    3838
     39#include <cassert>
    3940#include <list>
    4041#include <string>
     
    6869    class SignalHandler
    6970    {
    70     private:
    71         SignalHandler();
    7271    public:
    73         inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }
    74         ~SignalHandler(){ SignalHandler::singletonRef = NULL; }
     72        SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
     73        ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; }
     74        inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
    7575
    7676        void registerCallback( SignalCallback cb, void * someData );
     
    8787        SignalCallbackList callbackList;
    8888
    89         static SignalHandler * singletonRef;
     89        static SignalHandler* singletonRef_s;
    9090
    9191        std::string appName;
     
    104104    {
    105105    public:
    106         inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; };
    107         void doCatch( const std::string & appName, const std::string & filename ) {};
    108         void dontCatch() {};
    109         void registerCallback( SignalCallback cb, void * someData ) {};
     106        SignalHandler()  { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; }
     107        ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; }
     108        inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; }
     109        void doCatch( const std::string & appName, const std::string & filename ) {}
     110        void dontCatch() {}
     111        void registerCallback( SignalCallback cb, void * someData ) {}
    110112
    111113    private:
    112         static SignalHandler * singletonRef;
     114        static SignalHandler* singletonRef_s;
    113115    };
    114116}
Note: See TracChangeset for help on using the changeset viewer.