I have a few vectors that contain objects and I have a nested series of loops to get to the object I want
if (_dir->Instance()->isDebug())
{
Utils::LogTextWithInt("growing timers size: ", _glo->Instance()->getGrowingTimers().size());
for (int i=0; i < _glo->Instance()->getGrowingTimers().size(); i++)
{
GrowingTimer _growingTimer = _glo->Instance()->getGrowingTimers().at(i);
std::cout << "growing timer Field id and plant id: " << _growingTimer.getFieldID() << " - "
<< _growingTimer.getPlantID() << std::endl;
}
}
std::vector<GrowingTimer>::iterator _gtIterB = _glo->Instance()->getGrowingTimers().begin();
for (_gtIterB; _gtIterB != _glo->Instance()->getGrowingTimers().end(); ++_gtIterB)
{
for (std::vector<Field>::iterator _fIterB = _glo->Instance()->getFields().begin();
_fIterB != _glo->Instance()->getFields().end(); ++_fIterB)
{
if (_gtIterB->getFieldID() == _fIterB->getFieldNumber())
{
for (std::vector<Plant>::iterator _pIterB = _fIterB->getPlants().begin();
_pIterB != _fIterB->getPlants().end(); )
{
if (_gtIterB->getPlantID() == _pIterB->getPlantID())
{
Utils::LogText("gt and plant ID's match");
Utils::LogTextWithInt("Plant ID after matching: ", _pIterB->getPlantID());
// Wiggle our plant.
Utils::wiggleNode(_pIterB->getPlantSprite(), 10.0f, 5.0f);
_pIterB->setPlantStoppedGrowing(true);
_gtIterB = _glo->Instance()->getGrowingTimers().erase(_gtIterB);
++_pIterB;
}
else
{
++_pIterB;
}
}
}
}
}
The output is:
growing timers size: 2
growing timer Field id and plant id: 7620 - -2130819608
growing timer Field id and plant id: 7620 - -2130802800
gt field id: 7620
gt plant id: -2130819608
gt and plant ID's match
Plant ID after matching: -2130819608
deleted
gt and plant ID's match
Plant ID after matching: -2130802800
deleted
gt field id: 7620
gt plant id: -2130802800
gt and plant ID's match
Plant ID after matching: -2130802800
I am crashing after all of this:
0x209eff0: addb %ah, %gs:115(%ecx,%ebp,2)
0x209eff5: jo 0x209f063 ; "nitWithCondition:"
0x209eff7: popal
0x209eff8: jns 0x209f048 ; "'v'"
0x209effa: popal
0x209effb: insl
0x209effc: incl %esi
0x209effe: outsl
0x209efff: jb 0x209f04c ; "ckBeforeDate:"
0x209f001: jns 0x209f03e ; "Name:"
0x209f004: jbe 0x209f067 ; "ithCondition:"
0x209f006: insb
0x209f007: jne 0x209f06e ; "ition:"
0x209f009: cmpb (%eax), %al
0x209f00b: popl %edi
0x209f00c: jo 0x209f080 ; "lSinceNow"
Basically now that I have a match and I act upon it I want to delete the position in _gIterB
as it is no longer needed. This vector keeps getting added to as a "tracker" if you will of timed events that are running so that when the timers are finished we know what object the timer was for and can get back to it to do the next steps.
EDIT: The vector of GrowingTimer store the fieldID and the PlantID that is "growing" so we can get back to it.
The vector of Fields stores all the fields the user has and as a member each Field Object has a vector of the plants in the field. 8 plants to 1 field.
each field the user creates has a unique ID, the output below is there is one field with 2 plants in it.