瀏覽代碼

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.)
Andreas Kling 3 年之前
父節點
當前提交
96c9ca502b
共有 1 個文件被更改,包括 25 次插入0 次删除
  1. 25 0
      Userland/Libraries/LibWeb/Layout/FormattingContext.cpp

+ 25 - 0
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;
 }