Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 965fe05

Browse files
authored
[ASDisplayNode] Ensure that nil can never be returned from -measureWithSizeRange: (#2014)
* [ASDisplayNode] Ensure that nil can never be returned from -measureWithSizeRange: This can happen in rare cases when multiple relayouts occur while a transition is being measured. * [ASDisplayNode] Use ternary operator style for nil check.
1 parent e0ada47 commit 965fe05

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

AsyncDisplayKit/ASDisplayNode.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
642642
{
643643
ASDN::MutexLocker l(__instanceLock__);
644644
if (! [self shouldMeasureWithSizeRange:constrainedSize]) {
645-
return _calculatedLayout;
645+
ASDisplayNodeAssertNotNil(_calculatedLayout, @"-[ASDisplayNode measureWithSizeRange:] _layout should not be nil! %@", self);
646+
return _calculatedLayout ? : [ASLayout layoutWithLayoutableObject:self constrainedSizeRange:constrainedSize size:CGSizeZero];
646647
}
647648

648649
[self cancelLayoutTransitionsInProgress];
@@ -659,6 +660,7 @@ - (ASLayout *)measureWithSizeRange:(ASSizeRange)constrainedSize
659660
[self _completePendingLayoutTransition];
660661
}
661662

663+
ASDisplayNodeAssertNotNil(newLayout, @"-[ASDisplayNode measureWithSizeRange:] newLayout should not be nil! %@", self);
662664
return newLayout;
663665
}
664666

@@ -2071,6 +2073,8 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
20712073

20722074
layoutSpec.isMutable = NO;
20732075
ASLayout *layout = [layoutSpec measureWithSizeRange:constrainedSize];
2076+
ASDisplayNodeAssertNotNil(layout, @"[ASLayoutSpec measureWithSizeRange:] should never return nil! %@, %@", self, layoutSpec);
2077+
20742078
// Make sure layoutableObject of the root layout is `self`, so that the flattened layout will be structurally correct.
20752079
BOOL isFinalLayoutable = (layout.layoutableObject != self);
20762080
if (isFinalLayoutable) {

AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
// stretched children will have a cross dimension of at least crossMin
2929
const CGFloat childCrossMin = alignItems == ASStackLayoutAlignItemsStretch ? crossMin : 0;
3030
const ASSizeRange childSizeRange = directionSizeRange(style.direction, stackMin, stackMax, childCrossMin, crossMax);
31-
return [child measureWithSizeRange:childSizeRange];
31+
ASLayout *layout = [child measureWithSizeRange:childSizeRange];
32+
ASDisplayNodeCAssertNotNil(layout, @"ASLayout returned from measureWithSizeRange: must not be nil: %@", child);
33+
return layout ? : [ASLayout layoutWithLayoutableObject:child constrainedSizeRange:childSizeRange size:CGSizeZero];
3234
}
3335

3436
/**

0 commit comments

Comments
 (0)