From 95ab3d677cf1374cd8dcef667889dceb6fe7efd8 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 13 Apr 2016 15:26:50 -0700 Subject: [PATCH] must *always* be in main thread when dismissing view controller. (#1114) Fixes intermittent crash when uploading new group photos. // FREEBIE --- .../view controllers/NewGroupViewController.m | 85 +++++++++---------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/Signal/src/view controllers/NewGroupViewController.m b/Signal/src/view controllers/NewGroupViewController.m index 20fcef2ff..9e69f4cb1 100644 --- a/Signal/src/view controllers/NewGroupViewController.m +++ b/Signal/src/view controllers/NewGroupViewController.m @@ -142,59 +142,56 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue" inMessage:message thread:self.thread success:^{ - [self dismissViewControllerAnimated:YES - completion:^{ - [Environment messageGroup:self.thread]; - }]; - } + dispatch_async(dispatch_get_main_queue(), ^{ + [self dismissViewControllerAnimated:YES + completion:^{ + [Environment messageGroup:self.thread]; + }]; + }); + } failure:^{ - [self - dismissViewControllerAnimated:YES - completion:^{ - - [[TSStorageManager sharedManager] - .dbConnection - readWriteWithBlock:^( - YapDatabaseReadWriteTransaction *_Nonnull transaction) { - [self.thread removeWithTransaction:transaction]; - }]; - - SignalAlertView( - NSLocalizedString(@"GROUP_CREATING_FAILED", nil), - NSLocalizedString(@"NETWORK_ERROR_RECOVERY", nil)); - }]; - - }]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self dismissViewControllerAnimated:YES + completion:^{ + [TSStorageManager.sharedManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction){ + [self.thread removeWithTransaction:transaction]; + }]; + + SignalAlertView(NSLocalizedString(@"GROUP_CREATING_FAILED", nil), + NSLocalizedString(@"NETWORK_ERROR_RECOVERY", nil)); + } + ]; + }); + } + ]; } else { [[TSMessagesManager sharedManager] sendMessage:message inThread:self.thread success:^{ - [self dismissViewControllerAnimated:YES - completion:^{ - [Environment messageGroup:self.thread]; - }]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self dismissViewControllerAnimated:YES + completion:^{ + [Environment messageGroup:self.thread]; + } + ]; + }); } - failure:^{ - [self - dismissViewControllerAnimated:YES - completion:^{ + dispatch_async(dispatch_get_main_queue(), ^{ + [self dismissViewControllerAnimated:YES + completion:^{ + [TSStorageManager.sharedManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction){ + [self.thread removeWithTransaction:transaction]; + }]; + SignalAlertView(NSLocalizedString(@"GROUP_CREATING_FAILED", nil), + NSLocalizedString(@"NETWORK_ERROR_RECOVERY", nil)); + } + ]; + }); - [[TSStorageManager sharedManager] - .dbConnection - readWriteWithBlock:^( - YapDatabaseReadWriteTransaction *_Nonnull transaction) { - [self.thread removeWithTransaction:transaction]; - }]; - - SignalAlertView( - NSLocalizedString(@"GROUP_CREATING_FAILED", nil), - NSLocalizedString(@"NETWORK_ERROR_RECOVERY", nil)); - }]; - - - }]; + } + ]; } }]; }