Skip to content
Permalink
Browse files

Don't crash when iterating empty cache

  • Loading branch information
m-kuhn committed Nov 22, 2013
1 parent 3b20186 commit e9a37e968acfe6927227518b4dfb65d93f799ed7
Showing with 16 additions and 7 deletions.
  1. +15 −6 src/core/qgscachedfeatureiterator.cpp
  2. +1 −1 src/core/qgscachedfeatureiterator.h
@@ -21,7 +21,10 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
, mFeatureIds( featureIds )
, mVectorLayerCache( vlCache )
{
mFeatureIdIterator = featureIds.begin();
mFeatureIdIterator = featureIds.constBegin();

if ( mFeatureIdIterator == featureIds.constEnd() )
close();
}

QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache, QgsFeatureRequest featureRequest )
@@ -43,31 +46,37 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
break;
}

mFeatureIdIterator = mFeatureIds.begin();
mFeatureIdIterator = mFeatureIds.constBegin();

if ( mFeatureIdIterator == featureIds.constEnd() )
close();
}

bool QgsCachedFeatureIterator::fetchFeature( QgsFeature& f )
{
mFeatureIdIterator++;
if ( mClosed )
return false;

while ( mFeatureIdIterator != mFeatureIds.end() )
while ( mFeatureIdIterator++ != mFeatureIds.constEnd() )
{
f = QgsFeature( *mVectorLayerCache->mCache[*mFeatureIdIterator]->feature() );
if ( mRequest.acceptFeature( f ) )
return true;
}
close();
return false;
}

bool QgsCachedFeatureIterator::rewind()
{
mFeatureIdIterator = mFeatureIds.begin();
mFeatureIdIterator = mFeatureIds.constBegin();
return true;
}

bool QgsCachedFeatureIterator::close()
{
// Nothing to clean...
mClosed = true;
mFeatureIds.clear();
return true;
}

@@ -87,7 +87,7 @@ class CORE_EXPORT QgsCachedFeatureIterator : public QgsAbstractFeatureIterator
private:
QgsFeatureIds mFeatureIds;
QgsVectorLayerCache* mVectorLayerCache;
QgsFeatureIds::Iterator mFeatureIdIterator;
QgsFeatureIds::ConstIterator mFeatureIdIterator;
};

/**

0 comments on commit e9a37e9

Please sign in to comment.
You can’t perform that action at this time.