Skip to content

Commit

Permalink
Buffer polygons prior to passing them to QgsTessellator to fix crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 30, 2023
1 parent cf98644 commit cd8dd5d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/core/qgssggeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ QSGGeometry *QgsSGGeometry::qgsPolylineToQSGGeometry( const QgsPolylineXY &line,
QSGGeometry *QgsSGGeometry::qgsPolygonToQSGGeometry( const QgsPolygon *polygon, const QgsRectangle visibleExtent, double scaleFactor )
{
Q_ASSERT( polygon );

QgsGeometry geom( polygon->clone() );
geom = geom.buffer( 0.0000001, 5 );
QgsPolygon *bufferedPolygon = qgsgeometry_cast<QgsPolygon *>( geom.constGet() );

QgsTessellator t( visibleExtent.xMinimum(), visibleExtent.yMaximum(), false, false, false, true );
t.addPolygon( *polygon, 0 );
t.addPolygon( *bufferedPolygon, 0 );

QSGGeometry *sgGeom = new QSGGeometry( QSGGeometry::defaultAttributes_Point2D(), t.dataVerticesCount() );

Expand Down
6 changes: 4 additions & 2 deletions src/core/sgrubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ QSGGeometryNode *SGRubberband::createLineGeometry( const QVector<QgsPoint> &poin

QSGGeometryNode *SGRubberband::createPolygonGeometry( const QVector<QgsPoint> &points )
{
QgsPolygon polygon = QgsPolygon( new QgsLineString( points ) );
QgsGeometry geom( new QgsPolygon( new QgsLineString( points ) ) );
geom = geom.buffer( 0.0000001, 5 );
QgsPolygon *polygon = qgsgeometry_cast<QgsPolygon *>( geom.constGet() );
QgsTessellator t( 0, 0, false, false, false, true );
if ( points.size() > 2 )
{
t.addPolygon( polygon, 0 );
t.addPolygon( *polygon, 0 );
}

QSGGeometryNode *node = new QSGGeometryNode;
Expand Down

1 comment on commit cd8dd5d

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.