Fix bug while erasing from vectors

parent 21fa2fcc
Pipeline #21051 passed with stages
in 9 minutes and 18 seconds
...@@ -530,11 +530,17 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab) ...@@ -530,11 +530,17 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab)
// for(auto wall: walls ) // for(auto wall: walls )
// std::cout << wall.toString() << "\n"; // std::cout << wall.toString() << "\n";
// } // }
// getc(stdin);
// remove temp added walls // remove temp added walls
auto tempWalls = TempAddedWalls[tab->id]; auto tempWalls = TempAddedWalls[tab->id];
for(auto it=tempWalls.begin(); it!=tempWalls.end(); )
for(auto wall: tempWalls)
{ {
auto wall = *it;
if (it != tempWalls.end())
{
tempWalls.erase(it);
}
for (auto platform: _platforms) for (auto platform: _platforms)
{ {
// auto tracks = platform.second->tracks; // auto tracks = platform.second->tracks;
...@@ -542,17 +548,18 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab) ...@@ -542,17 +548,18 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab)
subroom_id = platform.second->sid; subroom_id = platform.second->sid;
// auto room = this->GetAllRooms().at(room_id); // auto room = this->GetAllRooms().at(room_id);
SubRoom * subroom = this->GetAllRooms().at(room_id)->GetAllSubRooms().at(subroom_id).get(); SubRoom * subroom = this->GetAllRooms().at(room_id)->GetAllSubRooms().at(subroom_id).get();
// std::cout << "----\n";
// for(auto subWall: subroom->GetAllWalls())
// std::cout << ">> "<< subWall.toString() << "\n";
// std::cout << "----\n";
for(auto subWall: subroom->GetAllWalls()) for(auto subWall: subroom->GetAllWalls())
{ {
if(subWall == wall) if(subWall == wall)
{ {
// if everything goes right, then we should enter this
// if. We already erased from tempWalls!
subroom->RemoveWall(wall); subroom->RemoveWall(wall);
// std::cout << KGRN << "RESET REMOVE wall " << wall.toString() << "\n" << RESET; // std::cout << KGRN << "RESET REMOVE wall " << wall.toString() << "\n" << RESET;
auto it = std::find(tempWalls.begin(), tempWalls.end(), wall);
if (it != tempWalls.end())
{
tempWalls.erase(it);
}
}//if }//if
}//subroom }//subroom
}//platforms }//platforms
...@@ -561,8 +568,13 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab) ...@@ -561,8 +568,13 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab)
/* // add remove walls */ /* // add remove walls */
auto tempRemovedWalls = TempRemovedWalls[tab->id]; auto tempRemovedWalls = TempRemovedWalls[tab->id];
for(auto wall: tempRemovedWalls) for(auto it=tempRemovedWalls.begin(); it!=tempRemovedWalls.end(); )
{ {
auto wall = *it;
if (it != tempRemovedWalls.end())
{
tempRemovedWalls.erase(it);
}
for (auto platform: _platforms) for (auto platform: _platforms)
{ {
auto tracks = platform.second->tracks; auto tracks = platform.second->tracks;
...@@ -578,11 +590,6 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab) ...@@ -578,11 +590,6 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab)
{ {
subroom->AddWall(wall); subroom->AddWall(wall);
// std::cout << KGRN << "ADD BACK wall " << wall.toString() << "\n" << RESET; // std::cout << KGRN << "ADD BACK wall " << wall.toString() << "\n" << RESET;
auto it = std::find(tempRemovedWalls.begin(), tempRemovedWalls.end(), wall);
if (it != tempRemovedWalls.end())
{
tempRemovedWalls.erase(it);
}
} }
} }
} }
...@@ -592,9 +599,13 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab) ...@@ -592,9 +599,13 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab)
/* // remove added doors */ /* // remove added doors */
auto tempDoors = TempAddedDoors[tab->id]; auto tempDoors = TempAddedDoors[tab->id];
for(auto it=tempDoors.begin(); it!=tempDoors.end(); )
for(auto door: tempDoors)
{ {
auto door = *it;
if (it != tempDoors.end())
{
tempDoors.erase(it);
}
for (auto platform: _platforms) for (auto platform: _platforms)
{ {
auto tracks = platform.second->tracks; auto tracks = platform.second->tracks;
...@@ -608,14 +619,7 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab) ...@@ -608,14 +619,7 @@ bool Building::resetGeometry(std::shared_ptr<TrainTimeTable> tab)
// Trnasitions are added to subrooms and building!! // Trnasitions are added to subrooms and building!!
subroom->RemoveTransition(subTrans); subroom->RemoveTransition(subTrans);
this->RemoveTransition(subTrans); this->RemoveTransition(subTrans);
// std::cout << KGRN << "RESET remove door " << door.toString() << "\n" << RESET; // std::cout << KGRN << "RESET remove door " << door.toString() << "\n" << RESET;
auto it = std::find(tempDoors.begin(), tempDoors.end(), door);
if (it != tempDoors.end())
{
tempDoors.erase(it);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment