From ad0705d126261b32d64c76bac4f831f8600d3d4d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 13 Nov 2015 18:30:12 -0800 Subject: [PATCH] Fix concurrent modification crash in app asset caching code --- .../ViewControllers/MainFrameViewController.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index f741e9a..21c4979 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -696,14 +696,14 @@ static NSMutableSet* hostList; _sortedAppList = [host.appList allObjects]; _sortedAppList = [_sortedAppList sortedArrayUsingSelector:@selector(compareName:)]; - // Start populating the box art cache asynchronously - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - Log(LOG_I, @"Starting per-computer box art caching job"); - for (App* app in host.appList) { + // Dispatch independent jobs to fetch each app art asset. This way we enumerate on the main thread + // which is safe for accessing the app list, and this also provides us the ability to use the sorted + // list to fetch items the user is more likely to view first. + for (App* app in _sortedAppList) { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self updateBoxArtCacheForApp:app]; - } - Log(LOG_I, @"Per-computer box art caching job completed"); - }); + }); + } [hostScrollView removeFromSuperview]; [self.collectionView reloadData];