Skip to content

Commit

Permalink
Additional safeguard: do not try to save a null preview image
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Dec 20, 2023
1 parent aa50eb1 commit e28825c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/qgismobileapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,10 +1363,13 @@ void QgisMobileapp::saveProjectPreviewImage()
if ( !mProjectFilePath.isEmpty() && mMapCanvas && !mMapCanvas->isRendering() )
{
const QImage grab = mMapCanvas->image();
const int pixels = std::min( grab.width(), grab.height() );
const QRect rect( ( grab.width() - pixels ) / 2, ( grab.height() - pixels ) / 2, pixels, pixels );
const QImage img = grab.copy( rect );
img.save( QStringLiteral( "%1.jpg" ).arg( mProjectFilePath ) );
if ( !grab.isNull() )
{
const int pixels = std::min( grab.width(), grab.height() );
const QRect rect( ( grab.width() - pixels ) / 2, ( grab.height() - pixels ) / 2, pixels, pixels );
const QImage img = grab.copy( rect );
img.save( QStringLiteral( "%1.jpg" ).arg( mProjectFilePath ) );
}
}
}

Expand Down

1 comment on commit e28825c

@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.