Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualConny14156

Posted 22 July 2013 - 06:43 AM

Hi,

I have this really wierd problem, where its not possible for me to free a certain memory.

 

My Initializilation code start like

Global->EntityController.NewEntity("test");
Entity* TestObject;
TestObject = Global->EntityController.RequestEntity("test");
TestObject.name = "blan";
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<RenderComponent>());
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<ModelHandler>());
TestObject->GetComponent_S<RenderComponent>()->StandardBox();

And heres the body of the Newentity function body

void EntityHandler::NewEntity(std::string name)
{
	Entity testing;
	testing.name = name;
	TotalEntity.push_back(testing);
}

I Just made a simple one where I just push back the value into a vector. The constructor for my Entity is

Entity::Entity()
{
	FactoryComponent cFactory;
	AddComponent(cFactory.ComponentInstantiate<TransformComponent>());
	AddComponent_S(cFactory.ComponentInstantiate_S<TransformComponent>());//<----- This one is the problem
}

I use a simple template system where I just return a "new" pointer into a vector inside Entity

template<class Component>
Component* ComponentInstantiate_S()
{
	Component* tC;	
	tC = new Component;
	return tC;
}

Works great for me, and I get no error. And I have no problem getting it added into my vector

void Entity::AddComponent_S(BaseComponent* type)
{
	if(ComponentList_S.count(type->getTypeName()) == 0)
	{
		type->setHolder(this);
		ComponentList_S.insert(std::make_pair(type->getTypeName(),type));
	}
}

The way I made it, is that all entity need to have a transform component, so I add one transform component whenever a entity gets initlized. 

The wierd part is that, I get no error and the transform component gets added to the vector. And seeing how I use push back on "testing" the object get copied into the vector. at the end of the function testing already reach the end of its life and ehm "die" and will call upon the destructor. The wierd part here is that I get no error.

for(std::map<std::string,BaseComponent*>::iterator it = ComponentList_S.begin(); it != ComponentList_S.end();it++)
{
	if(it->second)
	{
		it->second->Release();
		delete it->second;
		it->second = 0;
	}
}
ComponentList_S.clear();

But for some reason, just this one entity "Blan" where I creates with "NewEntity()" it pop up a error saying that I can't access this memory when the program reach to the delete section of the code.

I also want to point out that I added render component and modelhander outside of the constructor and both memory got freed without error's.

And when I try to remove the auto add transform component from the constructor and manual add it under the initializilation function

Global->EntityController.NewEntity("blan");
Entity* TestObject;
TestObject = Global->EntityController.RequestEntity("blan");

TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<TransformComponent>());//<--- Like so

TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<RenderComponent>());
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<ModelHandler>());
TestObject->GetComponent_S<RenderComponent>()->StandardBox();

Than it works as "intended" except the part that I need to add it manually.

 

Some help and info on this matter would be greatly appecirated,  and sorry for the bad english, not my mother tongue. 

 

Thanks you 


#2Conny14156

Posted 22 July 2013 - 06:38 AM

Hi,

I have this really wierd problem, where its not possible for me to free a certain memory.

 

My Initializilation code start like

Global->EntityController.NewEntity("test");
Entity* TestObject;
TestObject = Global->EntityController.RequestEntity("test");
TestObject.name = "blan";
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<RenderComponent>());
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<ModelHandler>());
TestObject->GetComponent_S<RenderComponent>()->StandardBox();

And heres the body of the Newentity function body

void EntityHandler::NewEntity(std::string name)
{
	Entity testing;
	testing.name = name;
	TotalEntity.push_back(testing);
}

I Just made a simple one where I just push back the value into a vector. The constructor for my Entity is

Entity::Entity()
{
	FactoryComponent cFactory;
	AddComponent(cFactory.ComponentInstantiate<TransformComponent>());
	AddComponent_S(cFactory.ComponentInstantiate_S<TransformComponent>());//<----- This one is the problem
}

I use a simple template system where I just return a "new" pointer into a vector inside Entity

template<class Component>
Component* ComponentInstantiate_S()
{
	Component* tC;	
	tC = new Component;
	return tC;
}

Works great for me, and I get no error. And I have no problem getting it added into my vector

void Entity::AddComponent_S(BaseComponent* type)
{
	if(ComponentList_S.count(type->getTypeName()) == 0)
	{
		type->setHolder(this);
		ComponentList_S.insert(std::make_pair(type->getTypeName(),type));
	}
}

Now comes the wierd part, The way I made it is that all entity have to have a transform component, so I add one transform component whenever a entity gets initlized. at my NewEntity (std::string) function, I just push back the object, as push back a copy of the object, the testing Entity will reach its end of life at the end of the function which trigger the Entity deconstructor. Which looks like

for(std::map<std::string,BaseComponent*>::iterator it = ComponentList_S.begin(); it != ComponentList_S.end();it++)
{
	if(it->second)
	{
		it->second->Release();
		delete it->second;
		it->second = 0;
	}
}
ComponentList_S.clear();

I get no error on the Entity "testing", its delete the transformcomponent from the vector without any complains. And its not the only one, I have other entity object that doesnt give error either.

but for some reason, just this one entity "Blan" where I creates with "NewEntity()" it pop up a error saying that I can't access this memory when the program reach to the delete section of the code.

I also want to point out that I added render component and modelhander outside of the constructor and both memory got freed without error's.

And when I try to remove the auto add transform component from the constructor and manual add it under the initializilation function

Global->EntityController.NewEntity("blan");
Entity* TestObject;
TestObject = Global->EntityController.RequestEntity("blan");

TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<TransformComponent>());//<--- Like so

TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<RenderComponent>());
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<ModelHandler>());
TestObject->GetComponent_S<RenderComponent>()->StandardBox();

Than it works as "intended" except the part that I need to add it manually.

 

Some help and info on this matter would be greatly appecirated,  and sorry for the bad english, not my mother tongue. 

 

Thanks you 


#1Conny14156

Posted 22 July 2013 - 06:37 AM

Hi,

I have this really wierd problem, where its not possible for me to free a certain memory.

 

My Initializilation code start like

Global->EntityController.NewEntity("test");
Entity* TestObject;
TestObject = Global->EntityController.RequestEntity("test");
TestObject.name = "blan";
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<RenderComponent>());
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<ModelHandler>());
TestObject->GetComponent_S<RenderComponent>()->StandardBox();

And heres the body of the first line function

void EntityHandler::NewEntity(std::string name)
{
	Entity testing;
	testing.name = name;
	TotalEntity.push_back(testing);
}

I Just made a simple one where I just push back the value into a vector. The constructor for my Entity is

Entity::Entity()
{
	FactoryComponent cFactory;
	AddComponent(cFactory.ComponentInstantiate<TransformComponent>());
	AddComponent_S(cFactory.ComponentInstantiate_S<TransformComponent>());//<----- This one is the problem
}

I use a simple template system where I just return a "new" pointer into a vector inside Entity

template<class Component>
Component* ComponentInstantiate_S()
{
	Component* tC;	
	tC = new Component;
	return tC;
}

Works great for me, and I get no error. And I have no problem getting it added into my vector

void Entity::AddComponent_S(BaseComponent* type)
{
	if(ComponentList_S.count(type->getTypeName()) == 0)
	{
		type->setHolder(this);
		ComponentList_S.insert(std::make_pair(type->getTypeName(),type));
	}
}

Now comes the wierd part, The way I made it is that all entity have to have a transform component, so I add one transform component whenever a entity gets initlized. at my NewEntity (std::string) function, I just push back the object, as push back a copy of the object, the testing Entity will reach its end of life at the end of the function which trigger the Entity deconstructor. Which looks like

for(std::map<std::string,BaseComponent*>::iterator it = ComponentList_S.begin(); it != ComponentList_S.end();it++)
{
	if(it->second)
	{
		it->second->Release();
		delete it->second;
		it->second = 0;
	}
}
ComponentList_S.clear();

I get no error on the Entity "testing", its delete the transformcomponent from the vector without any complains. And its not the only one, I have other entity object that doesnt give error either.

but for some reason, just this one entity "Blan" where I creates with "NewEntity()" it pop up a error saying that I can't access this memory when the program reach to the delete section of the code.

I also want to point out that I added render component and modelhander outside of the constructor and both memory got freed without error's.

And when I try to remove the auto add transform component from the constructor and manual add it under the initializilation function

Global->EntityController.NewEntity("blan");
Entity* TestObject;
TestObject = Global->EntityController.RequestEntity("blan");

TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<TransformComponent>());//<--- Like so

TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<RenderComponent>());
TestObject->AddComponent_S(cFactory.ComponentInstantiate_S<ModelHandler>());
TestObject->GetComponent_S<RenderComponent>()->StandardBox();

Than it works as "intended" except the part that I need to add it manually.

 

Some help and info on this matter would be greatly appecirated,  and sorry for the bad english, not my mother tongue. 

 

Thanks you 


PARTNERS