Index: GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCEntity.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCEntity.cpp	(revision 699)
+++ GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCEntity.cpp	(revision 721)
@@ -4,5 +4,5 @@
 namespace BBC {
 
-Entity::Entity() 
+Entity::Entity(): references(0) // initialize references to 0 
 {
 	createSubEntity();
@@ -11,23 +11,19 @@
 Entity::~Entity()	 
 {
-	for (unsigned int iSubEntity = 0; iSubEntity < getNumSubEntities(); iSubEntity++)
-	{
-		SubEntity *subEntity = getSubEntity(iSubEntity);
-		delete subEntity;
-	}
+
 }
 
 void Entity::createSubEntity()
 {
-	SubEntity *subEntity = new SubEntity();
-	mSubEntityList.push_back(subEntity);
-}
-
-void Entity::addSubEntity(SubEntity *value)
+	SubEntityPtr subEntityPtr((SubEntity*)new SubEntity());
+	mSubEntityList.push_back(subEntityPtr);
+}
+
+void Entity::addSubEntity(SubEntityPtr value)
 {
 	mSubEntityList.push_back(value);
 }
 
-SubEntity* Entity::getSubEntity(unsigned int index)
+SubEntityPtr Entity::getSubEntity(unsigned int index)
 {
 	return mSubEntityList[index];
@@ -36,7 +32,5 @@
 void Entity::removeSubEntity(unsigned int index)
 {
-	SubEntity *subEntity = mSubEntityList[index];
 	mSubEntityList.erase(mSubEntityList.begin()+index);
-	delete subEntity;
 }
 
@@ -57,10 +51,10 @@
 }
 
-Ogre::Mesh* Entity::getMesh() 
+MeshPtr Entity::getMesh() 
 {
 	return mMesh;
 }
 
-void Entity::setMesh(Ogre::Mesh *value) 
+void Entity::setMesh(MeshPtr value) 
 {
 	mMesh = value;
@@ -93,7 +87,7 @@
 void Entity::sincronizeNumSubEntities()
 {
-	if (this->getNumSubEntities() < mMesh->getNumSubMeshes())
-	{
-		while (this->getNumSubEntities() < mMesh->getNumSubMeshes())
+	if (this->getNumSubEntities() < mMesh->get()->getNumSubMeshes())
+	{
+		while (this->getNumSubEntities() < mMesh->get()->getNumSubMeshes())
 		{
 			this->createSubEntity();
@@ -101,7 +95,7 @@
 	}
 
-	if (this->getNumSubEntities() > mMesh->getNumSubMeshes())
-	{
-		while (this->getNumSubEntities() > mMesh->getNumSubMeshes())
+	if (this->getNumSubEntities() > mMesh->get()->getNumSubMeshes())
+	{
+		while (this->getNumSubEntities() > mMesh->get()->getNumSubMeshes())
 		{
 			this->removeSubEntity(this->getNumSubEntities()-1);
@@ -117,12 +111,12 @@
 	size_t next_offset = 0;
 
-	unsigned int numSubMeshes = mMesh->getNumSubMeshes();
+	unsigned int numSubMeshes = mMesh->get()->getNumSubMeshes();
 	sincronizeNumSubEntities();
 	
 	added_shared = false;
-	for (unsigned short i = 0; i < mMesh->getNumSubMeshes(); i++)
-	{
-		Ogre::SubMesh* subMesh = mMesh->getSubMesh(i);
-		Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->sharedVertexData : subMesh->vertexData;
+	for (unsigned short i = 0; i < mMesh->get()->getNumSubMeshes(); i++)
+	{
+		Ogre::SubMesh* subMesh = mMesh->get()->getSubMesh(i);
+		Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->get()->sharedVertexData : subMesh->vertexData;
 
 		if ((!subMesh->useSharedVertices) || (subMesh->useSharedVertices && !added_shared))
@@ -173,12 +167,12 @@
 	size_t next_offset = 0;
 
-	unsigned int numSubMeshes = mMesh->getNumSubMeshes();
+	unsigned int numSubMeshes = mMesh->get()->getNumSubMeshes();
 	sincronizeNumSubEntities();
 	
 	added_shared = false;
-	for (unsigned short i = 0; i < mMesh->getNumSubMeshes(); i++)
-	{
-		Ogre::SubMesh* subMesh = mMesh->getSubMesh(i);
-		Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->sharedVertexData : subMesh->vertexData;
+	for (unsigned short i = 0; i < mMesh->get()->getNumSubMeshes(); i++)
+	{
+		Ogre::SubMesh* subMesh = mMesh->get()->getSubMesh(i);
+		Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->get()->sharedVertexData : subMesh->vertexData;
 
 		if ((!subMesh->useSharedVertices) || (subMesh->useSharedVertices && !added_shared))
@@ -223,12 +217,12 @@
 	size_t next_offset = 0;
 
-	unsigned int numSubMeshes = mMesh->getNumSubMeshes();
+	unsigned int numSubMeshes = mMesh->get()->getNumSubMeshes();
 	sincronizeNumSubEntities();
 	
 	added_shared = false;
-	for (unsigned short i = 0; i < mMesh->getNumSubMeshes(); i++)
-	{
-		Ogre::SubMesh* subMesh = mMesh->getSubMesh(i);
-		Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->sharedVertexData : subMesh->vertexData;
+	for (unsigned short i = 0; i < mMesh->get()->getNumSubMeshes(); i++)
+	{
+		Ogre::SubMesh* subMesh = mMesh->get()->getSubMesh(i);
+		Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->get()->sharedVertexData : subMesh->vertexData;
 
 		if ((!subMesh->useSharedVertices) || (subMesh->useSharedVertices && !added_shared))
@@ -290,12 +284,12 @@
 	size_t next_offset = 0;
 
-	unsigned int numSubMeshes = mMesh->getNumSubMeshes();
+	unsigned int numSubMeshes = mMesh->get()->getNumSubMeshes();
 	sincronizeNumSubEntities();
 	
 	added_shared = false;
-	for (unsigned short i = 0; i < mMesh->getNumSubMeshes(); i++)
-	{
-		Ogre::SubMesh* subMesh = mMesh->getSubMesh(i);
-		Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->sharedVertexData : subMesh->vertexData;
+	for (unsigned short i = 0; i < mMesh->get()->getNumSubMeshes(); i++)
+	{
+		Ogre::SubMesh* subMesh = mMesh->get()->getSubMesh(i);
+		Ogre::VertexData* vertexData = subMesh->useSharedVertices ? mMesh->get()->sharedVertexData : subMesh->vertexData;
 
 		if ((!subMesh->useSharedVertices) || (subMesh->useSharedVertices && !added_shared))
@@ -411,5 +405,5 @@
 	size_t index_offset = 0;
 
-	unsigned int numSubMeshes = mMesh->getNumSubMeshes();
+	unsigned int numSubMeshes = mMesh->get()->getNumSubMeshes();
 	sincronizeNumSubEntities();
 
@@ -417,9 +411,9 @@
 
 	// Run through the submeshes again, adding the data into the arrays
-	for ( unsigned short i = 0; i < mMesh->getNumSubMeshes(); ++i)
-	{
-		Ogre::SubMesh* submesh = mMesh->getSubMesh(i);
-
-		Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mMesh->sharedVertexData : submesh->vertexData;
+	for ( unsigned short i = 0; i < mMesh->get()->getNumSubMeshes(); ++i)
+	{
+		Ogre::SubMesh* submesh = mMesh->get()->getSubMesh(i);
+
+		Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mMesh->get()->sharedVertexData : submesh->vertexData;
 
 		if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared))
@@ -497,5 +491,5 @@
 unsigned int Entity::getNumSubEntities()
 {
-	return static_cast<unsigned int>(mSubEntityList.size());
+	return mSubEntityList.size();
 }
 
@@ -530,13 +524,8 @@
 		for (unsigned int iSubEntity = 1; iSubEntity < mSubEntityList.size(); iSubEntity)
 		{
-			SubEntityList::iterator subEntityListIterator = mSubEntityList.begin()+iSubEntity;
-			// Gametools -- 02/03/2006
-			// BUG: If I delete the subentity other entities that reference it will lose it's data...
-			//SubEntity *subEntity = (*subEntityListIterator);
 			mSubEntityList.erase(mSubEntityList.begin()+iSubEntity);
-			//delete subEntity;
-		}
-	}
-}
-
-}
+		}
+	}
+}
+
+}
