Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Storing a list of resolutions as an array?  (Read 5348 times)

0 Members and 1 Guest are viewing this topic.

Flash619

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #15 on: November 15, 2012, 11:33:51 pm »

If all of your video modes were invalid, this loop would only be capable of removing half of them.  An element is skipped for every one removed, with the exception of the last element if it happens to be removed -- undefined behavior is invoked in that case.

Well it was equaling 0 entries after the loop. :/ Oh well, I don't even have that loop anymore. I obsoleted it after discovering how much I loved sf::VideoMode::getFullscreenModes()

Perde

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
Re: Storing a list of resolutions as an array?
« Reply #16 on: November 16, 2012, 12:04:50 am »
Just in case you wonder, this would be a proper way:
std::vector<sf::VideoMode>::iterator it = relist.begin();
while(it != relist.end())
{
    if(!it->isValid())
        it = relist.erase(it);
    else
        ++it;
}

Since erase removes the current element, the iterator points at the next one. That's why you only have to increase it when nothing gets removed, or else you'd skip elements.
« Last Edit: November 16, 2012, 12:09:56 am by Perde »