List iterator not incrementable

Recommended Posts

Hi, I have a little problem in my game which randomly pops up, so it seems. I get a Debug Assertion Failed error claiming that my list iterator is not incrementable. The call stack brings me to a simple piece of code:

I don't see how the iterator could not increment. If the iterator should reach the end of the list then the loop should break. If the last element gets erased the iterator should get the same value as lstBuffs.end() and the loop should break. So I'm guessing that the iterator getting incremented is somehow corrupt. So the question is, why is this happening?

Share this post

Link to post

Share on other sites

I just noticed however that I don't get any error if I don't call list::clear(). This happens outside the function I posted before. I don't understand why it makes a difference, after a call to clear the list should be empty and the loop should not start at all, but this seems not to be the case.

0

Share this post

Link to post

Share on other sites

So I did some more debugging, I am certain this problem only occurs if I call lstBuffs.clear(). The weird thing is that at the time this error occurs the debugger shows me the list is empty. However if I check for an empty list using lstBuffs.empty() before I run the function I still get the same error.