I am running argos3 simulation where sometimes I need to remove an entity from a family of entity types. Rarely I get this error:
Code: Select all
[FATAL] CSpace::RemoveEntity() : Entity "pellet509" has not been found in the indexes.
Code: Select all
std::ostringstream pelletId;
pelletId << "pellet" << pelletIdCounter;
CBoxEntity* pellet = new CBoxEntity(pelletId.str(),CVector3(robotPosition + CVector3(0.1,0.1,0)),CQuaternion(),true,CVector3(0.1,0.1,0.1),0.1);
AddEntity(*pellet);
pellets.push_back(pellet);
pelletIdCounter++;
Then at some point later in the simulation, I randomly remove a pellet:
Code: Select all
if (pellets.size() > 0) {
uint pelletId = uint(randNumGenerator->Uniform(CRange<Real>(0,pellets.size()-1)));
//-- try if it still exists in space indexes
CSpace::TMapPerType& pelletsInSpace = GetSpace().GetEntitiesByType("box");
CBoxEntity* pellet = any_cast<CBoxEntity*>(pelletsInSpace[pellets[pelletId]->GetId()]);
if (pellet != NULL) {
RemoveEntity(*pellet);
}
//-- remove from the array
pellets.erase(pellets.begin()+pelletId);
pellet = NULL;
}