Skip to content

Commit

Permalink
Fix a crash that could occur when cancelling an export (fixes #2192)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoagx committed Aug 2, 2015
1 parent b158c41 commit 9728737
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Source/SPExportController.m
Expand Up @@ -72,6 +72,9 @@ - (void)_toggleExportButtonWithBool:(NSNumber *)enable;
- (void)_resizeWindowForCustomFilenameViewByHeightDelta:(NSInteger)delta;
- (void)_resizeWindowForAdvancedOptionsViewByHeightDelta:(NSInteger)delta;

- (void)_waitUntilQueueIsEmpty:(id)sender;
- (void)_queueIsEmpty:(id)sender;

@end

@implementation SPExportController
Expand Down Expand Up @@ -364,8 +367,20 @@ - (IBAction)cancelExport:(id)sender
[sender setEnabled:NO];

// Cancel all of the currently running operations
[operationQueue cancelAllOperations];

[operationQueue cancelAllOperations]; // async call
[NSThread detachNewThreadWithName:SPCtxt(@"SPExportController cancelExport: waiting for empty queue", tableDocumentInstance) target:self selector:@selector(_waitUntilQueueIsEmpty:) object:sender];
}

- (void)_waitUntilQueueIsEmpty:(id)sender
{
[sender retain];
[operationQueue waitUntilAllOperationsAreFinished];
[self performSelectorOnMainThread:@selector(_queueIsEmpty:) withObject:sender waitUntilDone:NO];
[sender release];
}

- (void)_queueIsEmpty:(id)sender
{
// Loop the cached export file paths and remove them from disk if they exist
for (SPExportFile *file in exportFiles)
{
Expand Down

0 comments on commit 9728737

Please sign in to comment.