OK, so I have just the strangest problem and I can't figure out why it is happening.
I have this bit of code, which makes the error.
bool nextLayerBlocked = false;
for( unsigned int i = 0; i < interactiveElements.size() && nextLayerBlocked == false; ++i )
{
std::cout << "Processing layer " << i <<" of gui" << std::endl;
for( unsigned int j = 0; j < interactiveElements[i].size(); ++j )
{
std::cout << "Processing element " << j << " of layer " << i << std::endl;
interactiveElements[i][j]->HandleInput( userInput );
if( interactiveElements[i][j]->IsLayerBlocking() == true )
{
std::cout << "Next Layer is blocked" << std::endl;
nextLayerBlocked = true;
}
if( interactiveElements[i][j]->IsBlocking() == true )
{
std::cout << "Element is blocking" << std::endl;
activeElement = interactiveElements[i][j];
j = interactiveElements[i].size();
i = interactiveElements.size();
}
std::cout << "j = " << j << " i = " << i << std::endl;
}
}
Now, when ran in the debugger, it works exactly as expected. When not run in debugger, however, it crashes. What happens not in the debugger is that when an element blocks and it sets j and i to be equal to the sizes to exit the loop, the for loops ignore their check! The cout's report the numbers as being 1 larger than they are at the end, like the loops increase them by 1 and say, yup, these numbers are still smaller than the vector size. This in turn causes a segment fault.
What baffles me is the fact that it works fine when run through the debugger, but then fails when not. I don't understand. It's probably something small and stupid, but I can't find it.