Original Post
This is my first post on gamedev.net Right I am new to game programming and I am stuck with this problem since more than two hours now. Basically it is a small 2D game with bubbles and spiky things. I am stuck with the part where I need to check the collisions. I am getting the dreaded iterator cannot be referenced error. Moreover, its not crashing at the beginning or end of the loop its pretty random and I am not able to figure out if I am doing something wrong while erasing the element from list. in the beginning of the program I have instantiated objects of these classes. Bubbles* bubbles; Spikies* spikies; Both these classes have std::list of bubble instances( bubbleList)and spiky instances (spikyList) respectively Any input would be much appreciated. Thanks. [Edited by - ninthjarl on March 17, 2010 2:54:58 PM]
BubbleList::iterator bubbleIter;
SpikyList::iterator spikyIter;
bool isTouching = false;
bubbleIter = bubbles->bubbleList.begin();
if(!bubbles->bubbleList.empty())
{
while( bubbleIter != bubbles->bubbleList.end() )
{
isTouching = false;
for(spikyIter = spikies->spikyList.begin(); spikyIter != spikies->spikyList.end(); spikyIter++)
{
if( (*spikyIter)->mState == ALIVE)
isTouching = (*bubbleIter)->boundingCircle->Intersects((*spikyIter)->boundingCircle);
if(isTouching)
{
SAFE_DELETE(*bubbleIter);
bubbleIter = bubbles->bubbleList.erase(bubbleIter);
(*spikyIter)->mState = DEAD;
}
}
//checking if we are not at the end of the list
if( bubbleIter != bubbles->bubbleList.end())
++bubbleIter;
//check if list is empty
if( bubbles->bubbleList.empty() )
break;
}
}