From ac86cd9523b9c1f7f7e87a3aa30d91f1b04c0f73 Mon Sep 17 00:00:00 2001 From: Li Tan Date: Tue, 16 Dec 2014 20:03:28 -0800 Subject: [PATCH 1/2] Fix crash while deleting multiple sections --- AsyncDisplayKit/Details/ASDataController.mm | 8 +------- AsyncDisplayKit/Details/ASFlowLayoutController.mm | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/AsyncDisplayKit/Details/ASDataController.mm b/AsyncDisplayKit/Details/ASDataController.mm index b540c9c6..d4383fa0 100644 --- a/AsyncDisplayKit/Details/ASDataController.mm +++ b/AsyncDisplayKit/Details/ASDataController.mm @@ -402,13 +402,7 @@ static void *kASDataUpdatingQueueContext = &kASDataUpdatingQueueContext; [self syncUpdateDataWithBlock:^{ NSArray *indexPaths = ASIndexPathsForMultidimensionalArray(_nodes); - - // sort indexPath in reverse order to avoid messing up the index when inserting in several batches - NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath *obj1, NSIndexPath *obj2) { - return [obj2 compare:obj1]; - }]; - - DELETE_NODES(_nodes, sortedIndexPaths); + DELETE_NODES(_nodes, indexPaths); NSMutableIndexSet *indexSet = [[NSMutableIndexSet alloc] initWithIndexesInRange:NSMakeRange(0, _nodes.count)]; DELETE_SECTIONS(_nodes, indexSet); diff --git a/AsyncDisplayKit/Details/ASFlowLayoutController.mm b/AsyncDisplayKit/Details/ASFlowLayoutController.mm index f2e3af3b..7101a110 100644 --- a/AsyncDisplayKit/Details/ASFlowLayoutController.mm +++ b/AsyncDisplayKit/Details/ASFlowLayoutController.mm @@ -47,7 +47,7 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3; } - (void)deleteNodesAtIndexPaths:(NSArray *)indexPaths { - [indexPaths enumerateObjectsUsingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) { + [indexPaths enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(NSIndexPath *indexPath, NSUInteger idx, BOOL *stop) { std::vector &v = _nodeSizes[indexPath.section]; v.erase(v.begin() + indexPath.row); }]; From a22c4a2761905b7bef938256e583996383150510 Mon Sep 17 00:00:00 2001 From: Li Tan Date: Tue, 16 Dec 2014 20:11:31 -0800 Subject: [PATCH 2/2] Another case for deletion --- AsyncDisplayKit/Details/ASDataController.mm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/AsyncDisplayKit/Details/ASDataController.mm b/AsyncDisplayKit/Details/ASDataController.mm index d4383fa0..45b65f96 100644 --- a/AsyncDisplayKit/Details/ASDataController.mm +++ b/AsyncDisplayKit/Details/ASDataController.mm @@ -339,10 +339,8 @@ static void *kASDataUpdatingQueueContext = &kASDataUpdatingQueueContext; } - (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths { - // sort indexPath in revse order to avoid messing up the index when deleting - NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath *obj1, NSIndexPath *obj2) { - return [obj2 compare:obj1]; - }]; + // sort indexPath in order to avoid messing up the index when deleting + NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingSelector:@selector(compare:)]; dispatch_async([ASDataController sizingQueue], ^{ [self asyncUpdateDataWithBlock:^{