Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[3d] Fix crash if the input data contain some empty polygons
  • Loading branch information
wonder-sk committed Mar 10, 2019
1 parent 175ebae commit 3b98331
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/qgstessellator.cpp
Expand Up @@ -423,6 +423,11 @@ void QgsTessellator::addPolygon( const QgsPolygon &polygon, float extrusionHeigh
// Assuming that the coordinates should be in a projected CRS, we should be able
// to simplify geometries that may cause problems and avoid possible crashes
QgsGeometry polygonSimplified = QgsGeometry( polygonNew->clone() ).simplify( 0.001 );
if ( polygonSimplified.isNull() )
{
QgsMessageLog::logMessage( QObject::tr( "geometry simplification failed - skipping" ), QObject::tr( "3D" ) );
return;
}
const QgsPolygon *polygonSimplifiedData = qgsgeometry_cast<const QgsPolygon *>( polygonSimplified.constGet() );
if ( _minimum_distance_between_coordinates( *polygonSimplifiedData ) < 0.001 )
{
Expand Down
13 changes: 13 additions & 0 deletions tests/src/3d/testqgstessellator.cpp
Expand Up @@ -134,6 +134,7 @@ class TestQgsTessellator : public QObject
void testBadCoordinates();
void testIssue17745();
void testCrashSelfIntersection();
void testCrashEmptyPolygon();

private:
};
Expand Down Expand Up @@ -335,6 +336,18 @@ void TestQgsTessellator::testCrashSelfIntersection()
t.addPolygon( p, 0 ); // must not crash - that's all we test here
}

void TestQgsTessellator::testCrashEmptyPolygon()
{
// this is a polygon that goes through GEOS simplification which throws an exception (and produces null geometry)

QgsTessellator t( 0, 0, true );
QgsPolygon p;
bool resWktRead = p.fromWkt( "PolygonZ ((0 0 0, 0 0 0, 0 0 0))" );
QVERIFY( resWktRead );

t.addPolygon( p, 0 ); // must not crash - that's all we test here
}


QGSTEST_MAIN( TestQgsTessellator )
#include "testqgstessellator.moc"

0 comments on commit 3b98331

Please sign in to comment.