vector iterator not dereferencable

Started by
1 comment, last by lride 11 years, 4 months ago
I have this piece of code. This is called once every frame
[source lang="cpp"] //While there is a message to deliver
while(messageQueue.top().dispatchTime<=currentTime && !messageQueue.empty())
{
//deliver the message
messageQueue.top().receiver->handleMessage(messageQueue.top());
//delete the message
messageQueue.pop();
}[/source]

This works fine in release, but when I run in debug mode, I soon get an assertion failure: "Debug Assertion Failed! vector iterator not dereferencable"
An invisible text.
Advertisement
You should put the !messageQueue.empty() test before you attempt to dereference top(), in case the queue actually is empty which would mean that messageQueue.top().dispatchTime is trying to dereference end() iterator.
Thank you. That fixed it.
An invisible text.

This topic is closed to new replies.

Advertisement