Skip to content

Commit 9728737

Browse files
committed
Fix a crash that could occur when cancelling an export (fixes #2192)
1 parent b158c41 commit 9728737

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Source/SPExportController.m

+17-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ - (void)_toggleExportButtonWithBool:(NSNumber *)enable;
7272
- (void)_resizeWindowForCustomFilenameViewByHeightDelta:(NSInteger)delta;
7373
- (void)_resizeWindowForAdvancedOptionsViewByHeightDelta:(NSInteger)delta;
7474

75+
- (void)_waitUntilQueueIsEmpty:(id)sender;
76+
- (void)_queueIsEmpty:(id)sender;
77+
7578
@end
7679

7780
@implementation SPExportController
@@ -364,8 +367,20 @@ - (IBAction)cancelExport:(id)sender
364367
[sender setEnabled:NO];
365368

366369
// Cancel all of the currently running operations
367-
[operationQueue cancelAllOperations];
368-
370+
[operationQueue cancelAllOperations]; // async call
371+
[NSThread detachNewThreadWithName:SPCtxt(@"SPExportController cancelExport: waiting for empty queue", tableDocumentInstance) target:self selector:@selector(_waitUntilQueueIsEmpty:) object:sender];
372+
}
373+
374+
- (void)_waitUntilQueueIsEmpty:(id)sender
375+
{
376+
[sender retain];
377+
[operationQueue waitUntilAllOperationsAreFinished];
378+
[self performSelectorOnMainThread:@selector(_queueIsEmpty:) withObject:sender waitUntilDone:NO];
379+
[sender release];
380+
}
381+
382+
- (void)_queueIsEmpty:(id)sender
383+
{
369384
// Loop the cached export file paths and remove them from disk if they exist
370385
for (SPExportFile *file in exportFiles)
371386
{

0 commit comments

Comments
 (0)