I don't understand what you're trying to accomplish. The code you gave me has a number of issues.
This is a sample project. I tried to recreate the issue of my main project in it.
- In the loop functions, you have a loop over all the epuck. Within this loop, you erase all of the boxes. Why? Looping once over the boxes is enough.
- The way you erase the boxes does not work. You can iterate over a container and erase elements at the same time - this creates a memory corruption.
- The code is in the PreStep() method. This means that you add the boxes in Init(), allow ARGoS to take note of them, and then remove them before ARGoS has the possibility to update anything. This creates a memory corruption, which leads to the specific problem you're encountering.
Again, I'm not sure what you're trying to accomplish here, but if you want to delete stuff, do it in PostStep() and not in PreStep().
1. My main project is a foraging task. Each epuck picks up a food. In PostStep!, we detect the food and remove it. So it needs two FOR loops.
2. After each deletion, we break from the inner loop.
3. You're right. After replacing PreStep with PostStep, the issue is gone.
Thank you very much.