facebookarchive / AsyncDisplayKit

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

it throws an error on ipad/iphone simulator #720

Closed vikas4goyal closed 8 years ago

vikas4goyal commented 9 years ago

it throws an error on ipad/iphone simulator ?

Assertion failure in -[ASDisplayNode _displayBlockWithAsynchronous:isCancelledBlock:rasterizing:], /Users/maheshgupta/testDevelopment/moebeldeapp/Pods/AsyncDisplayKit/AsyncDisplayKit/Private/ASDisplayNode+AsyncDisplay.mm:178 2015-10-05 18:20:37.664 Presenting view controllers on detached view controllers is discouraged <ProductViewController: 0x7a63dfa0>. 2015-10-05 18:20:42.459 moebel.de[5164:854926] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid contents scale' * First throw call stack: ( 0 CoreFoundation 0x01b0fa94 exceptionPreprocess + 180 1 libobjc.A.dylib 0x015d0e02 objc_exception_throw + 50 2 CoreFoundation 0x01b0f92a +[NSException raise:format:arguments:] + 138 3 Foundation 0x012503e6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118 4 moebel.de 0x0012f39d -[ASDisplayNode(AsyncDisplay) _displayBlockWithAsynchronous:isCancelledBlock:rasterizing:] + 1869 5 moebel.de 0x00130e47 -[ASDisplayNode(AsyncDisplay) displayAsyncLayer:asynchronously:] + 1655 6 moebel.de 0x001ae9cf __27-[_ASDisplayLayer display:]_block_invoke + 95 7 moebel.de 0x001af000 -[_ASDisplayLayer _performBlockWithAsyncDelegate:] + 160 8 moebel.de 0x001ae91c -[_ASDisplayLayer display:] + 140 9 moebel.de 0x001ae86f -[_ASDisplayLayer display] + 527 10 QuartzCore 0x0263a078 _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 326 11 QuartzCore 0x0263a0fe _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 38 12 QuartzCore 0x0262cc2b _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317 13 QuartzCore 0x02660c23 _ZN2CA11Transaction6commitEv + 589 14 QuartzCore 0x026614d6 _ZN2CA11Transaction17observer_callbackEP19CFRunLoopObservermPv + 92 15 CoreFoundation 0x01a2977e CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 16 CoreFoundation 0x01a296de CFRunLoopDoObservers + 398 17 CoreFoundation 0x01a1f05c CFRunLoopRun + 1340 18 CoreFoundation 0x01a1e866 CFRunLoopRunSpecific + 470 19 CoreFoundation 0x01a1e67b CFRunLoopRunInMode + 123 20 GraphicsServices 0x04bb1664 GSEventRunModal + 192 21 GraphicsServices 0x04bb14a1 GSEventRun + 104 22 UIKit 0x02830cc1 UIApplicationMain + 160 23 moebel.de 0x000d60ea main + 138 24 libdyld.dylib 0x04316a21 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

vikas4goyal commented 9 years ago

this error randomly occurred and after error when i run it again. it runs perfectly

richardtop commented 9 years ago

Could you provide some code samples which cause the crash? I think, the initialization flow and viewDidLoad of presenting and presented ViewControllers may be helpful.

appleguy commented 9 years ago

@vikas4goyal I echo @richardoti — anyone who provides a runnable sample project here will get help very promptly, usually within hours, to debug almost any problem with their code!

I looked at this assertion for you. It is: ASDisplayNodeAssert(self.contentsScaleForDisplay != 0.0, @"Invalid contents scale");

Does your code have any reference to contentsScaleForDisplay, if you do a full text search of the project? I have never seen this issue reported, so it initially seems like it would be an issue where you set this property to 0. Unlike some other areas where you can set 0 and expect it to automatically use the screen scale, that's not the case for this property.

vikas4goyal commented 9 years ago

This is parent Class: // // AsyncCollectionCell.m

import "AsyncCollectionCell.h"

import "NSOperationQueueCache.h"

@interface AsyncCollectionCell () @property(strong,nonatomic)ASDisplayNode* containerNode; @property(strong,nonatomic)CALayer* placeholderlayer; @property(strong,nonatomic)NSOperation* nodeConstructionOperation; @end

@implementation AsyncCollectionCell

-(void)setup{ self.placeholderlayer =[CALayer layer]; self. placeholderlayer.backgroundColor=[UIColor colorWithWhite:0.95 alpha:1.0].CGColor; self. placeholderlayer.contentsScale=[UIScreen mainScreen].scale; [self.contentView.layer addSublayer:self.placeholderlayer]; }

-(void)prepareForReuse{ [super prepareForReuse]; [self.containerNode recursivelySetDisplaySuspended:YES]; [self.containerNode.layer removeFromSuperlayer]; self.containerNode=nil; if (self.nodeConstructionOperation) { [self.nodeConstructionOperation cancel]; self.nodeConstructionOperation=nil; } } -(void)layoutSubviews{ [super layoutSubviews]; [CATransaction begin]; [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; [self.placeholderlayer setFrame:self.bounds]; [CATransaction commit];

if (self.containerNode) {
    self.containerNode.frame = self.bounds;
}
[self layoutSubNodes:NO];

} -(void)setData:(id)dataObject{ if(self.nodeConstructionOperation){ [self.nodeConstructionOperation cancel]; self.nodeConstructionOperation=nil; } NSBlockOperation* newNodeConstructionOpration =[self createNodeConstructionOperation:dataObject]; self.nodeConstructionOperation =newNodeConstructionOpration; NSOperationQueue* commonQueue =[NSOperationQueueCache cacheOperationQueue:NSStringFromClass(self.class)]; [commonQueue addOperation:newNodeConstructionOpration]; }

pragma mark funtion for implement in subclass

-(void)configureNode:(id)data containerNode:(ASDisplayNode_)containerNode{ //should be implement in subclasses } -(void)layoutSubNodes:(BOOL)calculate{ //should be implement in subclasses }

pragma mark private

-(NSBlockOperation_)createNodeConstructionOperation:(id)data{ NSBlockOperation* blockOperation=[NSBlockOperation blockOperationWithBlock:^{ if ([blockOperation isCancelled]) { return ; } ASDisplayNode* containerNode=[[ASDisplayNode alloc] init]; containerNode.layerBacked=YES; containerNode.shouldRasterizeDescendants=YES; containerNode.contentsScale=[UIScreen mainScreen].scale; containerNode.backgroundColor=[UIColor colorWithWhite:0.95 alpha:1.0]; containerNode.frame=self.bounds; [self configureNode:data containerNode:containerNode]; [self layoutSubNodes:YES]; dispatch_async(dispatch_get_main_queue(), ^{ if ([blockOperation isCancelled]) { return ; } if (containerNode.displaySuspended) { return; } [self.contentView.layer addSublayer:containerNode.layer]; [containerNode setNeedsDisplay]; self.containerNode=containerNode; }); }]; return blockOperation; }

@end

//This is Child Class: // // AsyncProductCell.m //

import "AsyncProductCell.h"

import "Skinning.h"

import "NSAttributedString+Extra.h"

import "ProductCellModel.h"

import "NSString+ParserAndFormatter.h"

import "Color.h"

import "Font.h"

import "Image.h"

define TEXT_MARGIN 5.0

define CENTER_MARGIN 25.0

@interface AsyncProductCell () @property(strong, nonatomic) CALayer placeholderLayer; @property(strong, nonatomic) CALayer contentLayer; @property(weak,nonatomic)id imageDownloadOperation;

@end

@implementation AsyncProductCell

@end we are using AsyncDisplayKit to create Collection Cell. AsyncCollectionCell is parent cell and AsyncProductCell is child which extend AsyncCollectionCell.

we have done full text search in our project for "contentsScaleForDisplay" and didn't find any reference in our code base.

[cell setData:<data model object>];

this is initial call to bind data with CollectionCell

appleguy commented 9 years ago

@vikas4goyal ok, thanks, this was useful. It looks like this is related to rasterization.

Can you confirm that if you remove any calls to setShouldRasterizeDescendants:YES, that your code runs and works as expected?

Could you try leaving on rasterization, but removing the various calls you have to setContentsScale:?

It would be particularly useful to have a running sample project. From the code above I can't immediately tell if your cell class is an ASCellNode or something else. If it's an ASCellNode, note that -layoutSubviews will never be called (same for all nodes — manual layout should use the -layout method)

appleguy commented 9 years ago

@vikas4goyal any other updates on this? Was the issue resolved or did you get a chance to test the things I asked? Sorry for the back-and-forth, but in cases where sample code can't be provided, it's important to have a few rounds for debugging.

vikas4goyal commented 8 years ago

@appleguy hi sorry for late reply. i have created an sample project. . i have added/used same classes which i am using in my original project. sample project is commited on github: link: https://github.com/vikas4goyal/sample-project

please check if you found any mistake. basically only AsyncCollectionCell and AsyncProductCell are using AsyncDisplayKit.

appleguy commented 8 years ago

@vikas4goyal cool, thanks for the sample project! I'm glad to say that it works perfectly for me. I am running the project against the latest AsyncDisplayKit 1.9, which if you point cocoa pods to the github repository or specify 1.9, it should be linked up properly after calling "pod install" (if Xcode is closed). Note your Podfile appears to have the "curly quotes" in it, which can mess up Cocoapods (it looks like the latest version detects this and is able to work around it).

Please definitely reopen this task or file another issue if you run into any problems, whether it is a completely new one, or unable to get past this one (if so, please let me know if you can run examples/Kittens after doing pod install in that directory) Cheers!

appleguy commented 8 years ago

@vikas4goyal - this is using iOS 9.1 and an iPhone 6s simulator.

screen shot 2015-11-07 at 9 15 55 pm