Skip to content

Commit

Permalink
Merge pull request #33170 from elpaso/bugfix-gh33168-set-center-crash
Browse files Browse the repository at this point in the history
Check for empty rect before calling setExtent
  • Loading branch information
elpaso committed Nov 30, 2019
2 parents 80cf602 + 38ae170 commit bc00621
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -901,16 +901,20 @@ bool QgsMapCanvas::setReferencedExtent( const QgsReferencedRectangle &extent )

void QgsMapCanvas::setCenter( const QgsPointXY &center )
{
QgsRectangle r = mapSettings().extent();
double x = center.x();
double y = center.y();
setExtent(
QgsRectangle(
x - r.width() / 2.0, y - r.height() / 2.0,
x + r.width() / 2.0, y + r.height() / 2.0
),
true
const QgsRectangle r = mapSettings().extent();
const double x = center.x();
const double y = center.y();
const QgsRectangle rect(
x - r.width() / 2.0, y - r.height() / 2.0,
x + r.width() / 2.0, y + r.height() / 2.0
);
if ( ! rect.isEmpty() )
{
setExtent(
rect,
true
);
}
} // setCenter

QgsPointXY QgsMapCanvas::center() const
Expand Down

0 comments on commit bc00621

Please sign in to comment.