Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix tessellator crash with 2d triangle again
Fixes #39976
  • Loading branch information
uclaros committed Nov 18, 2020
1 parent bcc8816 commit 6bc2984
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/core/qgstessellator.cpp
Expand Up @@ -604,7 +604,7 @@ void QgsTessellator::addPolygon( const QgsPolygon &polygon, float extrusionHeigh
const double *zData = !mNoZ ? exterior->zData() : nullptr;
for ( int i = 0; i < 3; i++ )
{
float z = mNoZ ? 0 : *zData;
float z = !zData ? 0 : *zData;
if ( z < zMin )
zMin = z;
if ( z > zMax )
Expand All @@ -626,7 +626,10 @@ void QgsTessellator::addPolygon( const QgsPolygon &polygon, float extrusionHeigh
}
mData << p.first << p.second;
}
xData++; yData++; zData++;
xData++; yData++;
// zData can be nullptr if mNoZ or triangle is 2D
if ( zData )
zData++;
}

if ( mAddBackFaces )
Expand Down
3 changes: 2 additions & 1 deletion tests/src/3d/testqgstessellator.cpp
Expand Up @@ -406,7 +406,8 @@ void TestQgsTessellator::testCrash2DTriangle()
// test tessellation of a 2D triangle - https://github.com/qgis/QGIS/issues/36024
QgsPolygon polygon;
polygon.fromWkt( "Polygon((0 0, 42 0, 42 42, 0 0))" );
QgsTessellator t( 0, 0, true, false, false, true );
// must not be declared with mNoz = true
QgsTessellator t( 0, 0, true );
t.addPolygon( polygon, 0 ); // must not crash - that's all we test here
}

Expand Down

0 comments on commit 6bc2984

Please sign in to comment.