Skip to content

Commit

Permalink
Fix crash when creating spatial index from empty layer
Browse files Browse the repository at this point in the history
libspatialindex library throws an exception when trying to bulk load spatial index
and it is given an empty input data stream
  • Loading branch information
wonder-sk committed May 9, 2018
1 parent f2304c1 commit 914ceff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgsspatialindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class QgsSpatialIndexData : public QSharedData
// create R-tree
SpatialIndex::id_type indexId;

if ( inputStream )
if ( inputStream && inputStream->hasNext() )
mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, *inputStream, *mStorage, fillFactor, indexCapacity,
leafCapacity, dimension, variant, indexId );
else
Expand Down
7 changes: 7 additions & 0 deletions tests/src/core/testqgsspatialindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class TestQgsSpatialIndex : public QObject
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()
{
QgsSpatialIndex *index = new QgsSpatialIndex;
Expand Down

0 comments on commit 914ceff

Please sign in to comment.