diff options
author | MacDue <macdue@dueutil.tech> | 2022-08-16 17:12:04 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-18 15:58:05 +0200 |
commit | ffdcc60b03ef3a195db4fd1ab78b92a8e919fd1b (patch) | |
tree | 786b268e19343398709e003f2f226944944a32dc /Userland | |
parent | f9a685437f1ef8ee0ae8cc296cdc04a7aff83b68 (diff) | |
download | serenity-ffdcc60b03ef3a195db4fd1ab78b92a8e919fd1b.zip |
LibWeb: Avoid NaNs from zero-length gradient color stops
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/Painting/GradientPainting.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp index db39eea7c5..0f72c20d43 100644 --- a/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/GradientPainting.cpp @@ -177,7 +177,11 @@ void paint_linear_gradient(PaintContext& context, Gfx::IntRect const& gradient_r // For any given point between the two color stops, // determine the pointโs location as a percentage of the distance between the two color stops. // Let this percentage be P. - auto p = (position - previous_stop.position) / (next_stop.position - previous_stop.position); + auto stop_length = next_stop.position - previous_stop.position; + // FIXME: Avoids NaNs... Still not quite correct? + if (stop_length <= 0) + return 1; + auto p = (position - previous_stop.position) / stop_length; if (!next_stop.transition_hint.has_value()) return p; if (*next_stop.transition_hint >= 1) |