diff options
author | Andreas Kling <kling@serenityos.org> | 2022-07-11 23:53:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-12 02:46:21 +0200 |
commit | 96c9ca502bc19edc92ae624fc18b3cc293279feb (patch) | |
tree | 82d753e97353beadf3740022624e87a207444832 /Userland/Libraries/LibWeb | |
parent | 2f0657739b8d709fcbd42dfcdd1ccdcb61126798 (diff) | |
download | serenity-96c9ca502bc19edc92ae624fc18b3cc293279feb.zip |
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.)
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FormattingContext.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index cecd756fd1..9f1b60dc25 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -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; } |