Reland: Sanitize measure function results
Summary: D57285584 was reverted because we have service code with a faulty measure function, and adding logging to Yoga when invalid measurements were received was enough to spike error rate to elevated levels and block release. This is a reland of the below change, with a couple modifications: 1. We log warnings instead of errors, which from what I heard, shouldn't block release, but should still make signal 2. We only zero the dimension which was NaN, to preserve exact behavior ## Original We've started seeing assertion failures in Yoga where a `NaN` value makes its way to an `availableHeight` constraint when measuring Litho tree. Because it's only happening on Litho, I have some suspicion this might be originating from a Litho-specific measure function. This adds sanitization in Yoga to measure function results, where we will log an error, and set size to zero, if either dimension ends up being negative of `NaN`. This doesn't really help track down where the error was happening, but Yoga doesn't have great context to show this to begin with. If we see this is issue, next steps would be Litho internal intrumentation to find culprit. Changelog: [Internal] Reviewed By: sbuggay Differential Revision: D57473295 fbshipit-source-id: 979f1b9a51f5550a8d3ca534276ec191a3cb7b9e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
24f0c56cce
commit
fb53cb7443
@@ -10,6 +10,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <yoga/debug/AssertFatal.h>
|
#include <yoga/debug/AssertFatal.h>
|
||||||
|
#include <yoga/debug/Log.h>
|
||||||
#include <yoga/node/Node.h>
|
#include <yoga/node/Node.h>
|
||||||
#include <yoga/numeric/Comparison.h>
|
#include <yoga/numeric/Comparison.h>
|
||||||
|
|
||||||
@@ -49,12 +50,31 @@ Node::Node(Node&& node) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
YGSize Node::measure(
|
YGSize Node::measure(
|
||||||
float width,
|
float availableWidth,
|
||||||
MeasureMode widthMode,
|
MeasureMode widthMode,
|
||||||
float height,
|
float availableHeight,
|
||||||
MeasureMode heightMode) {
|
MeasureMode heightMode) {
|
||||||
return measureFunc_(
|
const auto size = measureFunc_(
|
||||||
this, width, unscopedEnum(widthMode), height, unscopedEnum(heightMode));
|
this,
|
||||||
|
availableWidth,
|
||||||
|
unscopedEnum(widthMode),
|
||||||
|
availableHeight,
|
||||||
|
unscopedEnum(heightMode));
|
||||||
|
|
||||||
|
if (yoga::isUndefined(size.height) || size.height < 0 ||
|
||||||
|
yoga::isUndefined(size.width) || size.width < 0) {
|
||||||
|
yoga::log(
|
||||||
|
this,
|
||||||
|
LogLevel::Warn,
|
||||||
|
"Measure function returned an invalid dimension to Yoga: [width=%f, height=%f]",
|
||||||
|
size.width,
|
||||||
|
size.height);
|
||||||
|
return {
|
||||||
|
.width = maxOrDefined(0.0f, size.width),
|
||||||
|
.height = maxOrDefined(0.0f, size.height)};
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Node::baseline(float width, float height) const {
|
float Node::baseline(float width, float height) const {
|
||||||
|
@@ -66,9 +66,9 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
YGSize measure(
|
YGSize measure(
|
||||||
float width,
|
float availableWidth,
|
||||||
MeasureMode widthMode,
|
MeasureMode widthMode,
|
||||||
float height,
|
float availableHeight,
|
||||||
MeasureMode heightMode);
|
MeasureMode heightMode);
|
||||||
|
|
||||||
bool hasBaselineFunc() const noexcept {
|
bool hasBaselineFunc() const noexcept {
|
||||||
|
Reference in New Issue
Block a user