[Orxonox-commit 282] r2927 - in trunk/src: core orxonox orxonox/gamestates orxonox/gui

rgrieder at orxonox.net rgrieder at orxonox.net
Sun Apr 19 23:00:00 CEST 2009


Author: rgrieder
Date: 2009-04-19 22:59:59 +0200 (Sun, 19 Apr 2009)
New Revision: 2927

Modified:
   trunk/src/core/Game.cc
   trunk/src/core/Game.h
   trunk/src/orxonox/Main.cc
   trunk/src/orxonox/gamestates/GSMainMenu.cc
   trunk/src/orxonox/gui/GUIManager.cc
Log:
Fixed three memory leaks and a bug.
@beni: Is deleting the "startGame" console command a problem or did we just forget to remove the comment characters?

Modified: trunk/src/core/Game.cc
===================================================================
--- trunk/src/core/Game.cc	2009-04-19 20:46:06 UTC (rev 2926)
+++ trunk/src/core/Game.cc	2009-04-19 20:59:59 UTC (rev 2927)
@@ -105,9 +105,9 @@
         // Destroy pretty much everyhting left
         delete this->core_;
 
-        // Delete all GameStates created by the macros
-        for (std::map<std::string, GameState*>::const_iterator it = allStates_s.begin(); it != allStates_s.end(); ++it)
-            delete it->second;
+        // Delete all the created nodes
+        for (std::vector<GameStateTreeNode*>::const_iterator it = this->allStateNodes_.begin(); it != this->allStateNodes_.end(); ++it)
+            delete *it;
 
         delete this->gameClock_;
 
@@ -319,6 +319,7 @@
                 if (this->rootStateNode_ != NULL)
                     ThrowException(GameState, "No two root GameStates are allowed!");
                 GameStateTreeNode* newNode = new GameStateTreeNode;
+                this->allStateNodes_.push_back(newNode);
                 newNode->state_ = newState;
                 newNode->parent_ = 0;
                 this->rootStateNode_ = newNode;
@@ -327,6 +328,7 @@
             else if (currentNode)
             {
                 GameStateTreeNode* newNode = new GameStateTreeNode;
+                this->allStateNodes_.push_back(newNode);
                 newNode->state_ = newState;
                 if (newLevel < currentLevel)
                 {
@@ -390,4 +392,12 @@
         // just a required dummy return value
         return true;
     }
+
+    /*static*/ void Game::destroyStates()
+    {
+        // Delete all GameStates created by the macros
+        for (std::map<std::string, GameState*>::const_iterator it = allStates_s.begin(); it != allStates_s.end(); ++it)
+            delete it->second;
+        allStates_s.clear();
+    }
 }

Modified: trunk/src/core/Game.h
===================================================================
--- trunk/src/core/Game.h	2009-04-19 20:46:06 UTC (rev 2926)
+++ trunk/src/core/Game.h	2009-04-19 20:59:59 UTC (rev 2927)
@@ -76,6 +76,7 @@
         void addTickTime(uint32_t length);
 
         static bool addGameState(GameState* state);
+        static void destroyStates();
         static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
 
     private:
@@ -94,6 +95,7 @@
         GameStateTreeNode*              rootStateNode_;
         GameStateTreeNode*              activeStateNode_;
         std::vector<GameStateTreeNode*> requestedStateNodes_;
+        std::vector<GameStateTreeNode*> allStateNodes_;
 
         Core*                           core_;
         Clock*                          gameClock_;

Modified: trunk/src/orxonox/Main.cc
===================================================================
--- trunk/src/orxonox/Main.cc	2009-04-19 20:46:06 UTC (rev 2926)
+++ trunk/src/orxonox/Main.cc	2009-04-19 20:59:59 UTC (rev 2927)
@@ -68,6 +68,9 @@
         );
 
         orxonox.run();
+
+        // destroy the GameStates created pre-mainly
+        orxonox::Game::destroyStates();
     } // orxonox gets destroyed right here!
 
     // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)

Modified: trunk/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSMainMenu.cc	2009-04-19 20:46:06 UTC (rev 2926)
+++ trunk/src/orxonox/gamestates/GSMainMenu.cc	2009-04-19 20:59:59 UTC (rev 2927)
@@ -85,13 +85,16 @@
         InputManager::getInstance().requestLeaveState("mainMenu");
         InputManager::getInstance().requestDestroyState("mainMenu");
 
-/*
+        GUIManager::getInstance().setCamera(0);
+        GraphicsManager::getInstance().setCamera(0);
+        this->scene_->getSceneManager()->destroyCamera(this->camera_);
+        delete this->scene_;
+
         if (this->ccStartGame_)
         {
             delete this->ccStartGame_;
             this->ccStartGame_ = 0;
         }
-*/
     }
 
     void GSMainMenu::update(const Clock& time)

Modified: trunk/src/orxonox/gui/GUIManager.cc
===================================================================
--- trunk/src/orxonox/gui/GUIManager.cc	2009-04-19 20:46:06 UTC (rev 2926)
+++ trunk/src/orxonox/gui/GUIManager.cc	2009-04-19 20:59:59 UTC (rev 2927)
@@ -251,7 +251,10 @@
     */
     void GUIManager::setCamera(Ogre::Camera* camera)
     {
-        this->guiRenderer_->setTargetSceneManager(camera->getSceneManager());
+        if (camera == NULL)
+            this->guiRenderer_->setTargetSceneManager(0);
+        else
+            this->guiRenderer_->setTargetSceneManager(camera->getSceneManager());
     }
 
     /**




More information about the Orxonox-commit mailing list