From 551371cd190570ae910191393d17a695a7af812c Mon Sep 17 00:00:00 2001 From: Pavel Iohin Date: Fri, 20 Jan 2023 10:29:33 +0300 Subject: [PATCH] fixed crash with nan dimensions Fatal Exception: CALayerInvalidGeometry CALayer position contains NaN: [nan nan]. --- Sources/YogaKit/YGLayout.mm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sources/YogaKit/YGLayout.mm b/Sources/YogaKit/YGLayout.mm index da264c2f..e2781df2 100644 --- a/Sources/YogaKit/YGLayout.mm +++ b/Sources/YogaKit/YGLayout.mm @@ -502,11 +502,17 @@ static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin) YGNodeLayoutGetLeft(node), YGNodeLayoutGetTop(node), }; - - const CGPoint bottomRight = { + CGPoint bottomRight = { topLeft.x + YGNodeLayoutGetWidth(node), topLeft.y + YGNodeLayoutGetHeight(node), }; + + if (isnan(bottomRight.x)) { + bottomRight.x = 0; + } + if (isnan(bottomRight.y)) { + bottomRight.y = 0; + } const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero; view.frame = (CGRect) { @@ -515,8 +521,8 @@ static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin) .y = YGRoundPixelValue(topLeft.y + origin.y), }, .size = { - .width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x), - .height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y), + .width = MAX(0, YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x)), + .height = MAX(0, YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y)), }, };