Your logic isn't right for what it appears you want to do. You are not iterating through the two lists the way that you think you are. Once I started in on your code, I ended up doing a bit more than I intended. You will want to compare what I did with your own and figure out the reason for all the differences. You will also want to check that what I am presuming your intent was is correct. (Also, this is off the top of my head, I haven't tried compiling it.)
BubbleList::iterator bubbleIter;
SpikyList::iterator spikyIter;
bool isTouching = false;
bubbleIter = bubbles->bubbleList.begin();
while( bubbleIter != bubbles->bubbleList.end() )
{
isTouching = false;
for( spikyIter = spikies->spikyList.begin();
spikyIter != spikies->spikyList.end();
spikyIter++ )
{
if( (*spikyIter)->mState == ALIVE &&
(*bubbleIter)->boundingCircle->Intersects((*spikyIter)->boundingCircle) )
{
isTouching = true;
(*spikyIter)->mState = DEAD;
}
}
if( isTouching )
{
SAFE_DELETE(*bubbleIter);
bubbleIter = bubbles->bubbleList.erase(bubbleIter);
}
else
++bubbleIter;
}
At a second look over your code, I believe that I have spotted the immediate source of your reported error. It should be rectified by my revision above.
Consider the scenario that you have a bubble at the end of the bubble list that is touching a spiky that is not at the end of the spiky list.
In your original inner loop you will delete that bubble and remove it from the bubble list. In doing so, you advance your bubbleIter to bubbleList.end() - no longer an actual list entry. Since you are not at the end of the spiky list, your inner loop continues executing. It tries to check if the next spiky is touching the bubble now indicated by bubbleIter. But that is not a bubble, it is bubbleList.end(). You try to access it. Boom! Clear now? You really either wanted to terminate the inner loop early or defer deleting the bubble and advancing bubbleIter until after that loop finished.