Skip to content

Commit

Permalink
LibGfx: Fix crash when calling draw_triangle_wave() offscreen
Browse files Browse the repository at this point in the history
I think this regressed in SerenityOS#5018. It easily triggered when scrolling
a page that uses `text-decoration-style: wavy`.
  • Loading branch information
nico committed Nov 16, 2024
1 parent 4678fc1 commit 44bfee2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Tests/LibGfx/TestPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ TEST_CASE(draw_rect_rough_bounds)
painter.draw_rect(Gfx::IntRect(0, 0, 1, 1), Color::Black, true);
painter.draw_rect(Gfx::IntRect(9, 9, 1, 1), Color::Black, true);
}

TEST_CASE(draw_triangle_wave)
{
auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { 10, 10 }));
Gfx::Painter painter(*bitmap);
for (int y = -3; y < bitmap->height() + 3; ++y)
painter.draw_triangle_wave({0, y}, {bitmap->width(), y}, Gfx::Color::Red, 3, 2);
}
2 changes: 2 additions & 0 deletions Userland/Libraries/LibGfx/Painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,8 @@ void Painter::draw_physical_pixel(IntPoint physical_position, Color color, int t

IntRect rect { physical_position, { thickness, thickness } };
rect.intersect(clip_rect() * scale());
if (rect.is_empty())
return;
fill_physical_rect(rect, color);
}

Expand Down

0 comments on commit 44bfee2

Please sign in to comment.