diff --git a/Source/ASDisplayNode+Yoga.mm b/Source/ASDisplayNode+Yoga.mm index 97e7cb56b..038459fa4 100644 --- a/Source/ASDisplayNode+Yoga.mm +++ b/Source/ASDisplayNode+Yoga.mm @@ -15,6 +15,7 @@ #import #import #import +#import #import #import #import @@ -183,6 +184,13 @@ - (ASLayout *)layoutForYogaNode CGSize size = CGSizeMake(YGNodeLayoutGetWidth(yogaNode), YGNodeLayoutGetHeight(yogaNode)); CGPoint position = CGPointMake(YGNodeLayoutGetLeft(yogaNode), YGNodeLayoutGetTop(yogaNode)); + if (!ASIsCGSizeValidForSize(size)) { + size = CGSizeZero; + } + + if (!ASIsCGPositionValidForLayout(position)) { + position = CGPointZero; + } return [ASLayout layoutWithLayoutElement:self size:size position:position sublayouts:nil]; } @@ -205,6 +213,9 @@ - (void)setupYogaCalculatedLayout // The layout for self should have position CGPointNull, but include the calculated size. CGSize size = CGSizeMake(YGNodeLayoutGetWidth(yogaNode), YGNodeLayoutGetHeight(yogaNode)); + if (!ASIsCGSizeValidForSize(size)) { + size = CGSizeZero; + } ASLayout *layout = [ASLayout layoutWithLayoutElement:self size:size sublayouts:sublayouts]; #if ASDISPLAYNODE_ASSERTIONS_ENABLED @@ -398,11 +409,10 @@ - (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize NSLog(@"******************** STARTING YOGA -> ASLAYOUT CREATION ********************"); NSLog(@"****************************************************************************"); ASDisplayNodePerformBlockOnEveryYogaChild(self, ^(ASDisplayNode * _Nonnull node) { - NSLog(@" "); // Newline NSLog(@"node = %@", node); - NSLog(@"style = %@", node.style); - NSLog(@"layout = %@", node.yogaCalculatedLayout); - YGNodePrint(node.yogaNode, (YGPrintOptions)(YGPrintOptionsStyle | YGPrintOptionsLayout)); + YGNodePrint(node.style.yogaNode, (YGPrintOptions)(YGPrintOptionsStyle | YGPrintOptionsLayout)); + NSCAssert(ASIsCGSizeValidForSize(node.yogaCalculatedLayout.size), @"Yoga layout returned an invalid size"); + NSLog(@" "); // Newline }); } #endif /* YOGA_LAYOUT_LOGGING */ diff --git a/Source/Layout/ASDimension.h b/Source/Layout/ASDimension.h index 0cad40d27..0b3c6b7be 100644 --- a/Source/Layout/ASDimension.h +++ b/Source/Layout/ASDimension.h @@ -27,9 +27,10 @@ ASDISPLAYNODE_INLINE BOOL AS_WARN_UNUSED_RESULT ASIsCGSizeValidForLayout(CGSize return (ASPointsValidForLayout(size.width) && ASPointsValidForLayout(size.height)); } +// Note we want YGUndefined (10E20) to be considered invalid, so we have picked a smaller number than CGFLOAT_MAX/2.0 ASDISPLAYNODE_INLINE BOOL AS_WARN_UNUSED_RESULT ASPointsValidForSize(CGFloat points) { - return ((isnormal(points) || points == 0.0) && points >= 0.0 && points < (FLT_MAX / 2.0)); + return ((isnormal(points) || points == 0.0) && points >= 0.0 && points < 10000000.0); } ASDISPLAYNODE_INLINE BOOL AS_WARN_UNUSED_RESULT ASIsCGSizeValidForSize(CGSize size) @@ -37,9 +38,10 @@ ASDISPLAYNODE_INLINE BOOL AS_WARN_UNUSED_RESULT ASIsCGSizeValidForSize(CGSize si return (ASPointsValidForSize(size.width) && ASPointsValidForSize(size.height)); } +// Note we want YGUndefined (10E20) to be considered invalid, so we have picked a smaller number than CGFLOAT_MAX/2.0 ASDISPLAYNODE_INLINE BOOL ASIsCGPositionPointsValidForLayout(CGFloat points) { - return ((isnormal(points) || points == 0.0) && points < (CGFLOAT_MAX / 2.0)); + return ((isnormal(points) || points == 0.0) && points < 10000000.0); } ASDISPLAYNODE_INLINE BOOL ASIsCGPositionValidForLayout(CGPoint point)