Skip to content

Commit 914ceff

Browse files
committedMay 9, 2018
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
1 parent f2304c1 commit 914ceff

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
 

‎src/core/qgsspatialindex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class QgsSpatialIndexData : public QSharedData
220220
// create R-tree
221221
SpatialIndex::id_type indexId;
222222

223-
if ( inputStream )
223+
if ( inputStream && inputStream->hasNext() )
224224
mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, *inputStream, *mStorage, fillFactor, indexCapacity,
225225
leafCapacity, dimension, variant, indexId );
226226
else

‎tests/src/core/testqgsspatialindex.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class TestQgsSpatialIndex : public QObject
9999
QVERIFY( fids2.contains( 3 ) );
100100
}
101101

102+
void testInitFromEmptyIterator()
103+
{
104+
QgsFeatureIterator it;
105+
QgsSpatialIndex index( it );
106+
// we just test that we survive the above command without exception from libspatialindex raised
107+
}
108+
102109
void testCopy()
103110
{
104111
QgsSpatialIndex *index = new QgsSpatialIndex;

0 commit comments

Comments
 (0)