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/orxonox
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.