Fix crash when creating spatial index from empty layer

libspatialindex library throws an exception when trying to bulk load spatial index
and it is given an empty input data stream
This commit is contained in:
Martin Dobias 2018-05-08 16:16:11 -04:00
parent f2304c1b15
commit 914cefff95
2 changed files with 8 additions and 1 deletions

View File

@ -220,7 +220,7 @@ class QgsSpatialIndexData : public QSharedData
// create R-tree // create R-tree
SpatialIndex::id_type indexId; SpatialIndex::id_type indexId;
if ( inputStream ) if ( inputStream && inputStream->hasNext() )
mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, *inputStream, *mStorage, fillFactor, indexCapacity, mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, *inputStream, *mStorage, fillFactor, indexCapacity,
leafCapacity, dimension, variant, indexId ); leafCapacity, dimension, variant, indexId );
else else

View File

@ -99,6 +99,13 @@ class TestQgsSpatialIndex : public QObject
QVERIFY( fids2.contains( 3 ) ); QVERIFY( fids2.contains( 3 ) );
} }
void testInitFromEmptyIterator()
{
QgsFeatureIterator it;
QgsSpatialIndex index( it );
// we just test that we survive the above command without exception from libspatialindex raised
}
void testCopy() void testCopy()
{ {
QgsSpatialIndex *index = new QgsSpatialIndex; QgsSpatialIndex *index = new QgsSpatialIndex;