diff --git a/src/core/qgstessellator.cpp b/src/core/qgstessellator.cpp index 15fe52c6fccf..0becca04f327 100644 --- a/src/core/qgstessellator.cpp +++ b/src/core/qgstessellator.cpp @@ -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( polygonSimplified.constGet() ); if ( _minimum_distance_between_coordinates( *polygonSimplifiedData ) < 0.001 ) { diff --git a/tests/src/3d/testqgstessellator.cpp b/tests/src/3d/testqgstessellator.cpp index 651dc459b538..0aebb19724fb 100644 --- a/tests/src/3d/testqgstessellator.cpp +++ b/tests/src/3d/testqgstessellator.cpp @@ -134,6 +134,7 @@ class TestQgsTessellator : public QObject void testBadCoordinates(); void testIssue17745(); void testCrashSelfIntersection(); + void testCrashEmptyPolygon(); private: }; @@ -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"