Skip to content
Permalink
Browse files

[3d] Fix crash if the input data contain some empty polygons

  • Loading branch information
wonder-sk committed Mar 10, 2019
1 parent 175ebae commit 3b9833150201ac11f4e90676d845dff27513ea7f
Showing with 18 additions and 0 deletions.
  1. +5 −0 src/core/qgstessellator.cpp
  2. +13 −0 tests/src/3d/testqgstessellator.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<const QgsPolygon *>( polygonSimplified.constGet() );
if ( _minimum_distance_between_coordinates( *polygonSimplifiedData ) < 0.001 )
{
@@ -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"

0 comments on commit 3b98331

Please sign in to comment.
You can’t perform that action at this time.