From 36bcd63c0c6adddc6882285e305f3dc52b46c518 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sun, 12 Sep 2021 22:51:17 -0400 Subject: [PATCH] PixelPaint: Ensure thickness of shapes is never 0 when drawing When drawing a line/rectangle/ellipse in `Tool::on_second_paint()`, if `m_thickness * m_editor->scale()` was less than one, it would get converted to 0 because of truncation. This was causing infinite loops somewhere in the painter code and causing the application to freeze. Fixes #9986. --- Userland/Applications/PixelPaint/EllipseTool.cpp | 2 +- Userland/Applications/PixelPaint/LineTool.cpp | 2 +- Userland/Applications/PixelPaint/RectangleTool.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/PixelPaint/EllipseTool.cpp b/Userland/Applications/PixelPaint/EllipseTool.cpp index 6fd331eca8..5ace7869b5 100644 --- a/Userland/Applications/PixelPaint/EllipseTool.cpp +++ b/Userland/Applications/PixelPaint/EllipseTool.cpp @@ -101,7 +101,7 @@ void EllipseTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) painter.add_clip_rect(event.rect()); auto preview_start = m_editor->layer_position_to_editor_position(*layer, m_ellipse_start_position).to_type(); auto preview_end = m_editor->layer_position_to_editor_position(*layer, m_ellipse_end_position).to_type(); - draw_using(painter, preview_start, preview_end, m_thickness * m_editor->scale()); + draw_using(painter, preview_start, preview_end, AK::max(m_thickness * m_editor->scale(), 1)); } void EllipseTool::on_keydown(GUI::KeyEvent& event) diff --git a/Userland/Applications/PixelPaint/LineTool.cpp b/Userland/Applications/PixelPaint/LineTool.cpp index db673e0580..23e92b4602 100644 --- a/Userland/Applications/PixelPaint/LineTool.cpp +++ b/Userland/Applications/PixelPaint/LineTool.cpp @@ -109,7 +109,7 @@ void LineTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) painter.add_clip_rect(event.rect()); auto preview_start = m_editor->layer_position_to_editor_position(*layer, m_line_start_position).to_type(); auto preview_end = m_editor->layer_position_to_editor_position(*layer, m_line_end_position).to_type(); - painter.draw_line(preview_start, preview_end, m_editor->color_for(m_drawing_button), m_thickness * m_editor->scale()); + painter.draw_line(preview_start, preview_end, m_editor->color_for(m_drawing_button), AK::max(m_thickness * m_editor->scale(), 1)); } void LineTool::on_keydown(GUI::KeyEvent& event) diff --git a/Userland/Applications/PixelPaint/RectangleTool.cpp b/Userland/Applications/PixelPaint/RectangleTool.cpp index c1c08bcb8a..ec3bceeb1b 100644 --- a/Userland/Applications/PixelPaint/RectangleTool.cpp +++ b/Userland/Applications/PixelPaint/RectangleTool.cpp @@ -107,7 +107,7 @@ void RectangleTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) painter.add_clip_rect(event.rect()); auto start_position = m_editor->layer_position_to_editor_position(*layer, m_rectangle_start_position).to_type(); auto end_position = m_editor->layer_position_to_editor_position(*layer, m_rectangle_end_position).to_type(); - draw_using(painter, start_position, end_position, m_thickness * m_editor->scale()); + draw_using(painter, start_position, end_position, AK::max(m_thickness * m_editor->scale(), 1)); } void RectangleTool::on_keydown(GUI::KeyEvent& event)