facebookarchive / AsyncDisplayKit

Smooth asynchronous user interfaces for iOS apps.
http://asyncdisplaykit.org
Other
13.4k stars 2.2k forks source link

*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0] -[ASDisplayNode calculateLayoutThatFits:] #3284

Closed Bayonetta closed 7 years ago

Bayonetta commented 7 years ago

In our app, we received lots of crash infos about AsyncDisplayKit in Fabric.

It can be located on the 1146 line in ASDisplayNode.mm file.

The reason is the layout property is null. But we don't know why it will be happened. We're using version 2.2.1.

Following is call tree log, maybe will be helpful:

Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x18f9f21c0 exceptionPreprocess 1 libobjc.A.dylib 0x18e42c55c objc_exception_throw 2 CoreFoundation 0x18f8d1600 -[NSPlaceholderArray initWithObjects:count:] 3 CoreFoundation 0x18f8dd38c +[NSArray arrayWithObjects:count:] 4 WeiboOverseas 0x10046e634 -[ASDisplayNode calculateLayoutThatFits:] (ASDisplayNode.mm:1146) 5 WeiboOverseas 0x10046e3cc -[ASDisplayNode calculateLayoutThatFits:restrictedToSize:relativeToParentSize:] (ASDisplayNode.mm:1072) 6 WeiboOverseas 0x10046db38 -[ASDisplayNode layoutThatFits:parentSize:] (ASDisplayNode.mm:890) 7 WeiboOverseas 0x10048626c -[ASInsetLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:] (ASInsetLayoutSpec.mm:103) 8 WeiboOverseas 0x10048d574 -[ASLayoutSpec layoutThatFits:parentSize:] (ASLayoutSpec.mm:100) 9 WeiboOverseas 0x1004aae90 crossChildLayout(ASStackLayoutSpecChild const&, ASStackLayoutSpecStyle const&, double, double, double, double, CGSize) (ASStackUnpositionedLayout.mm:63) 10 WeiboOverseas 0x1004aa2f4 ASStackUnpositionedLayout::compute(std::1::vector<ASStackLayoutSpecChild, std::1::allocator > const&, ASStackLayoutSpecStyle const&, ASSizeRange const&) (ASStackUnpositionedLayout.mm:476) 11 WeiboOverseas 0x1004a92cc -[ASStackLayoutSpec calculateLayoutThatFits:] (ASStackLayoutSpec.mm:133) 12 WeiboOverseas 0x10048d6d8 -[ASLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:] (ASLayoutSpec.mm:109) 13 WeiboOverseas 0x10048d574 -[ASLayoutSpec layoutThatFits:parentSize:] (ASLayoutSpec.mm:100) 14 WeiboOverseas 0x1004aae90 crossChildLayout(ASStackLayoutSpecChild const&, ASStackLayoutSpecStyle const&, double, double, double, double, CGSize) (ASStackUnpositionedLayout.mm:63) 15 WeiboOverseas 0x1004aa2f4 ASStackUnpositionedLayout::compute(std::1::vector<ASStackLayoutSpecChild, std::1::allocator > const&, ASStackLayoutSpecStyle const&, ASSizeRange const&) (ASStackUnpositionedLayout.mm:476) 16 WeiboOverseas 0x1004a92cc -[ASStackLayoutSpec calculateLayoutThatFits:] (ASStackLayoutSpec.mm:133) 17 WeiboOverseas 0x10048d6d8 -[ASLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:] (ASLayoutSpec.mm:109) 18 WeiboOverseas 0x10048d574 -[ASLayoutSpec layoutThatFits:parentSize:] (ASLayoutSpec.mm:100) 19 WeiboOverseas 0x10048626c -[ASInsetLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:] (ASInsetLayoutSpec.mm:103) 20 WeiboOverseas 0x10048d574 -[ASLayoutSpec layoutThatFits:parentSize:] (ASLayoutSpec.mm:100) 21 WeiboOverseas 0x1004aae90 crossChildLayout(ASStackLayoutSpecChild const&, ASStackLayoutSpecStyle const&, double, double, double, double, CGSize) (ASStackUnpositionedLayout.mm:63) 22 WeiboOverseas 0x1004aa2f4 ASStackUnpositionedLayout::compute(std::1::vector<ASStackLayoutSpecChild, std::1::allocator > const&, ASStackLayoutSpecStyle const&, ASSizeRange const&) (ASStackUnpositionedLayout.mm:476) 23 WeiboOverseas 0x1004a92cc -[ASStackLayoutSpec calculateLayoutThatFits:] (ASStackLayoutSpec.mm:133) 24 WeiboOverseas 0x10048d6d8 -[ASLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:] (ASLayoutSpec.mm:109) 25 WeiboOverseas 0x10048d574 -[ASLayoutSpec layoutThatFits:parentSize:] (ASLayoutSpec.mm:100) 26 WeiboOverseas 0x10048626c -[ASInsetLayoutSpec calculateLayoutThatFits:restrictedToSize:relativeToParentSize:] (ASInsetLayoutSpec.mm:103) 27 WeiboOverseas 0x10048d574 -[ASLayoutSpec layoutThatFits:parentSize:] (ASLayoutSpec.mm:100) 28 WeiboOverseas 0x10046e59c -[ASDisplayNode calculateLayoutThatFits:] (ASDisplayNode.mm:1138) 29 WeiboOverseas 0x10046e3cc -[ASDisplayNode calculateLayoutThatFits:restrictedToSize:relativeToParentSize:] (ASDisplayNode.mm:1072) 30 WeiboOverseas 0x10046db38 -[ASDisplayNode layoutThatFits:parentSize:] (ASDisplayNode.mm:890) 31 WeiboOverseas 0x10045c2b0 -[ASDataController _layoutNode:withConstrainedSize:] (ASDataController.mm:179) 32 WeiboOverseas 0x10045c844 45-[ASDataController _layoutNodesFromContexts:]_blockinvoke (ASDataController.mm:228) 33 WeiboOverseas 0x100462108 ZL15ASDispatchApplymPU28objcproto17OS_dispatch_queue8NSObjectmU13block_pointerFvmE_block_invoke (ASDispatch.h:26) 34 libdispatch.dylib 0x18e87d200 _dispatch_call_block_and_release 35 libdispatch.dylib 0x18e87d1c0 _dispatch_client_callout 36 libdispatch.dylib 0x18e88bb18 _dispatch_queue_override_invoke 37 libdispatch.dylib 0x18e88d38c _dispatch_root_queue_drain 38 libdispatch.dylib 0x18e88d0ec _dispatch_worker_thread3 39 libsystem_pthread.dylib 0x18ea862b8 _pthread_wqthread 40 libsystem_pthread.dylib 0x18ea85da4 start_wqthread

maicki commented 7 years ago

@Bayonetta Hey, it seems in ASInsetLayoutSpec, layoutThatFits:parentSize is called on the child node. In the child node's calculateLayoutThatFits:, layoutThatFits: is called on the node that returns nil. We have a specific assertion for this in place at line 1140 in ASDisplayNode.m. Did you never hit it under development?

ASDisplayNodeAssertNotNil(layout, @"[ASLayoutElement layoutThatFits:] should never return nil! %@, %@", self, layout);

Could there be any case that you return 'nil' from layoutSpecThatFits:. As you can see a bit up, we call _layoutElementThatFits: on the child node and if that already returns nil, calling layoutThatFits: on a nil object will result also in a nil layout.

Bayonetta commented 7 years ago

Thanks @maicki , because we never meet this assert take effect in debug mode. I have checked all the custom nodes in our project and actually found a snippet may return nil in thelayoutSpecThatFits method.

I have fixed it and will keep watching it for incoming several days. I guess it should be worked 🍺