Skip to content

Commit

Permalink
QuickShow: Fix crash on startup
Browse files Browse the repository at this point in the history
QSWidget::relayout get triggered before setting a bitmap to display
while setting the widget as the main widget of the window.

I've added a null check to the paint event too to make sure the
widget works with no bitmap set.
  • Loading branch information
xTibor authored and awesomekling committed Apr 5, 2020
1 parent 4e54d0f commit 192513e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Applications/QuickShow/QSWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void QSWidget::set_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap)

void QSWidget::relayout()
{
if (m_bitmap.is_null())
return;

Gfx::Size new_size;
float scale_factor = (float)m_scale / 100.0f;
new_size.set_width(m_bitmap->width() * scale_factor);
Expand All @@ -65,6 +68,9 @@ void QSWidget::resize_event(GUI::ResizeEvent& event)

void QSWidget::paint_event(GUI::PaintEvent& event)
{
if (m_bitmap.is_null())
return;

GUI::Painter painter(*this);
painter.add_clip_rect(event.rect());

Expand Down

0 comments on commit 192513e

Please sign in to comment.