Index: code/branches/pch/src/core/Game.cc
===================================================================
--- code/branches/pch/src/core/Game.cc	(revision 3116)
+++ code/branches/pch/src/core/Game.cc	(revision 3124)
@@ -37,4 +37,5 @@
 #include <exception>
 #include <cassert>
+#include <boost/weak_ptr.hpp>
 
 #include "util/Debug.h"
@@ -51,4 +52,7 @@
 namespace orxonox
 {
+    using boost::shared_ptr;
+    using boost::weak_ptr;
+
     static void stop_game()
         { Game::getInstance().stop(); }
@@ -57,7 +61,7 @@
     struct _CoreExport GameStateTreeNode
     {
-        GameState*                      state_;
-        GameStateTreeNode*              parent_;
-        std::vector<GameStateTreeNode*> children_;
+        GameState* state_;
+        weak_ptr<GameStateTreeNode> parent_;
+        std::vector<shared_ptr<GameStateTreeNode> > children_;
     };
 
@@ -73,7 +77,4 @@
         assert(singletonRef_s == 0);
         singletonRef_s = this;
-
-        this->rootStateNode_ = 0;
-        this->activeStateNode_ = 0;
 
         this->abort_ = false;
@@ -105,8 +106,4 @@
         // Destroy pretty much everyhting left
         delete this->core_;
-
-        // 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_;
@@ -172,6 +169,6 @@
             {
                 // Note: this->requestedStateNodes_.front() is the currently active state node
-                std::vector<GameStateTreeNode*>::iterator it = this->requestedStateNodes_.begin() + 1;
-                if (*it == this->activeStateNode_->parent_)
+                std::vector<shared_ptr<GameStateTreeNode> >::iterator it = this->requestedStateNodes_.begin() + 1;
+                if (*it == this->activeStateNode_->parent_.lock())
                     this->unloadState(this->activeStateNode_->state_);
                 else // has to be child
@@ -226,5 +223,5 @@
         while (!this->activeStates_.empty())
             this->unloadState(this->activeStates_.back());
-        this->activeStateNode_ = 0;
+        this->activeStateNode_.reset();
         this->requestedStateNodes_.clear();
     }
@@ -251,8 +248,8 @@
             return;
 
-        GameStateTreeNode* requestedNode = 0;
+        shared_ptr<GameStateTreeNode> requestedNode;
 
         // this->requestedStateNodes_.back() is the currently active state
-        GameStateTreeNode* lastRequestedNode = this->requestedStateNodes_.back();
+        shared_ptr<GameStateTreeNode> lastRequestedNode = this->requestedStateNodes_.back();
 
         // Already the active node?
@@ -274,10 +271,10 @@
 
         // Check parent and all its grand parents
-        GameStateTreeNode* currentNode = lastRequestedNode;
+        shared_ptr<GameStateTreeNode> currentNode = lastRequestedNode;
         while (requestedNode == NULL && currentNode != NULL)
         {
             if (currentNode->state_ == state)
                 requestedNode = currentNode;
-            currentNode = currentNode->parent_;
+            currentNode = currentNode->parent_.lock();
         }
 
@@ -297,6 +294,6 @@
     void Game::popState()
     {
-        if (this->activeStateNode_ != NULL && this->requestedStateNodes_.back()->parent_)
-            this->requestState(this->requestedStateNodes_.back()->parent_->state_->getName());
+        if (this->activeStateNode_ != NULL && this->requestedStateNodes_.back()->parent_.lock())
+            this->requestState(this->requestedStateNodes_.back()->parent_.lock()->state_->getName());
         else
             COUT(2) << "Warning: Could not pop GameState. Ignoring." << std::endl;
@@ -333,5 +330,5 @@
         }
         unsigned int currentLevel = 0;
-        GameStateTreeNode* currentNode = 0;
+        shared_ptr<GameStateTreeNode> currentNode;
         for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
         {
@@ -346,8 +343,6 @@
                 if (this->rootStateNode_ != NULL)
                     ThrowException(GameState, "No two root GameStates are allowed!");
-                GameStateTreeNode* newNode = new GameStateTreeNode;
-                this->allStateNodes_.push_back(newNode);
+                shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode);
                 newNode->state_ = newState;
-                newNode->parent_ = 0;
                 this->rootStateNode_ = newNode;
                 currentNode = this->rootStateNode_;
@@ -355,6 +350,5 @@
             else if (currentNode)
             {
-                GameStateTreeNode* newNode = new GameStateTreeNode;
-                this->allStateNodes_.push_back(newNode);
+                shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode);
                 newNode->state_ = newState;
                 if (newLevel < currentLevel)
@@ -362,5 +356,5 @@
                     // Get down the hierarchy
                     do
-                        currentNode = currentNode->parent_;
+                        currentNode = currentNode->parent_.lock();
                     while (newLevel < --currentLevel);
                 }
@@ -369,5 +363,5 @@
                     // same level
                     newNode->parent_ = currentNode->parent_;
-                    newNode->parent_->children_.push_back(newNode);
+                    newNode->parent_.lock()->children_.push_back(newNode);
                 }
                 else if (newLevel == currentLevel + 1)
Index: code/branches/pch/src/core/Game.h
===================================================================
--- code/branches/pch/src/core/Game.h	(revision 3116)
+++ code/branches/pch/src/core/Game.h	(revision 3124)
@@ -41,4 +41,5 @@
 #include <map>
 #include <vector>
+#include <boost/shared_ptr.hpp>
 #include "OrxonoxClass.h"
 
@@ -106,8 +107,7 @@
 
         std::vector<GameState*>         activeStates_;
-        GameStateTreeNode*              rootStateNode_;
-        GameStateTreeNode*              activeStateNode_;
-        std::vector<GameStateTreeNode*> requestedStateNodes_;
-        std::vector<GameStateTreeNode*> allStateNodes_;
+        boost::shared_ptr<GameStateTreeNode> rootStateNode_;
+        boost::shared_ptr<GameStateTreeNode> activeStateNode_;
+        std::vector<boost::shared_ptr<GameStateTreeNode> > requestedStateNodes_;
 
         Core*                           core_;
