1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:18:14 +00:00

LibWeb: Add safety mechanism to guard against non-finite layout sizes

Due to some yet-to-be-found bug(s) in intrinsic sizing, we can sometimes
end up deciding that some box has a non-finite intrinsic size.

This will create unpleasant results, and may lead to some layout
algorithms looping infinitely, so this patch adds a safeguard where
we simply turn non-finite intrinsic sizes into zero (and complain a
little bit in the debug log.)
This commit is contained in:
Andreas Kling 2022-07-11 23:53:52 +02:00
parent 2f0657739b
commit 96c9ca502b

View file

@ -873,6 +873,13 @@ float FormattingContext::calculate_min_content_width(Layout::Box const& box) con
} else {
cache.min_content_width = context->greatest_child_width(box);
}
if (!isfinite(*cache.min_content_width)) {
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
dbgln("FIXME: Calculated non-finite min-content width for {}", box.debug_description());
cache.min_content_width = 0;
}
return *cache.min_content_width;
}
@ -904,6 +911,12 @@ float FormattingContext::calculate_max_content_width(Layout::Box const& box) con
cache.max_content_width = context->greatest_child_width(box);
}
if (!isfinite(*cache.max_content_width)) {
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
dbgln("FIXME: Calculated non-finite max-content width for {}", box.debug_description());
cache.max_content_width = 0;
}
return *cache.max_content_width;
}
@ -935,6 +948,12 @@ float FormattingContext::calculate_min_content_height(Layout::Box const& box) co
cache.min_content_height = calculate_auto_height(throwaway_state, box);
}
if (!isfinite(*cache.min_content_height)) {
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
dbgln("FIXME: Calculated non-finite min-content height for {}", box.debug_description());
cache.min_content_height = 0;
}
return *cache.min_content_height;
}
@ -966,6 +985,12 @@ float FormattingContext::calculate_max_content_height(Layout::Box const& box) co
cache.max_content_height = calculate_auto_height(throwaway_state, box);
}
if (!isfinite(*cache.max_content_height)) {
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
dbgln("FIXME: Calculated non-finite max-content height for {}", box.debug_description());
cache.max_content_height = 0;
}
return *cache.max_content_height;
}