This method causes an abort error: "map/set iterator not incrementable."
Due to that after the if
fails and a vaild iterator that should be erased is determined, (and is), continuing to the next iterator in the map via ++_iter
fails because _iter
is no longer a valid object/pointer.
What is the correct procedure for iterating through a map AND having the ability to remove individual items throughout?
typedef std::map<std::string, BITMAP*> MapStrBmp;
typedef MapStrBmp::iterator MapStrBmpIter;
\\...
void BitmapCache::CleanCache() {
//Clean the cache of any NULL bitmaps that were deleted by caller.
for(MapStrBmpIter _iter = _cache.begin(); _iter != _cache.end(); ++_iter) {
if(_iter->second != NULL) {
if((_iter->second->w < 0 && _iter->second->h < 0) == false) continue;
}
_cache.erase(_iter);
}
}
You just have to be a bit more careful: