Skip to content

Commit

Permalink
Fix a case of „background thread updating UI“ that could cause an exc…
Browse files Browse the repository at this point in the history
…eption with a very specific timing (#2754)
  • Loading branch information
dmoagx committed Mar 31, 2017
1 parent 64929b3 commit 5a201e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Source/SPCustomQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
// Reload table list if at least one query began with drop, alter, rename, or create
if(tableListNeedsReload || databaseWasChanged) {
// Build database pulldown menu
[tableDocumentInstance setDatabases:self];
[[tableDocumentInstance onMainThread] setDatabases:self];

if (databaseWasChanged)
// Reset the current database
Expand Down
4 changes: 2 additions & 2 deletions Source/SPDataImport.m
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,10 @@ - (void)importSQLFile:(NSString *)filename
}

// Update available databases
[tableDocumentInstance setDatabases:self];
[[tableDocumentInstance onMainThread] setDatabases:self];

// Update current selected database
[[tableDocumentInstance onMainThread] refreshCurrentDatabase];
[tableDocumentInstance refreshCurrentDatabase];

// Update current database tables
[tablesListInstance updateTables:self];
Expand Down
46 changes: 32 additions & 14 deletions Source/SPDatabaseDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ - (IBAction)backForwardInHistory:(id)sender
#pragma mark -
#pragma mark Connection callback and methods

/**
*
* This method *MUST* be called from the UI thread!
*/
- (void)setConnection:(SPMySQLConnection *)theConnection
{
if ([theConnection userTriggeredDisconnect]) {
Expand Down Expand Up @@ -617,6 +621,8 @@ - (void)setKeychainID:(NSString *)theId

/**
* sets up the database select toolbar item
*
* This method *MUST* be called from the UI thread!
*/
- (IBAction)setDatabases:(id)sender;
{
Expand Down Expand Up @@ -1171,6 +1177,8 @@ -(void)showErrorSheetWith:(NSArray *)error

/**
* Reset the current selected database name
*
* This method MAY be called from UI and background threads!
*/
- (void)refreshCurrentDatabase
{
Expand All @@ -1188,23 +1196,21 @@ - (void)refreshCurrentDatabase
dbName = NSArrayObjectAtIndex(eachRow, 0);
}

// TODO: there have been crash reports because dbName == nil at this point. When could that happen?
if(dbName && ![dbName isNSNull]) {
if(![dbName isEqualToString:selectedDatabase]) {
SPMainQSync(^{
// TODO: there have been crash reports because dbName == nil at this point. When could that happen?
if(dbName && ![dbName isNSNull]) {
if(![dbName isEqualToString:selectedDatabase]) {
if (selectedDatabase) SPClear(selectedDatabase);
selectedDatabase = [[NSString alloc] initWithString:dbName];
[chooseDatabaseButton selectItemWithTitle:selectedDatabase];
[self updateWindowTitle:self];
}
} else {
if (selectedDatabase) SPClear(selectedDatabase);
selectedDatabase = [[NSString alloc] initWithString:dbName];
[chooseDatabaseButton selectItemWithTitle:selectedDatabase];
#ifndef SP_CODA /* [self updateWindowTitle:self] */
[chooseDatabaseButton selectItemAtIndex:0];
[self updateWindowTitle:self];
#endif
}
} else {
if (selectedDatabase) SPClear(selectedDatabase);
[chooseDatabaseButton selectItemAtIndex:0];
#ifndef SP_CODA /* [self updateWindowTitle:self] */
[self updateWindowTitle:self];
#endif
}
});
}

//query finished
Expand Down Expand Up @@ -6071,6 +6077,10 @@ - (void)setIsSavedInBundle:(BOOL)savedInBundle

#ifndef SP_CODA /* whole database operations */

/**
*
* This method *MUST* be called from the UI thread!
*/
- (void)_copyDatabase
{
if ([[databaseCopyNameField stringValue] isEqualToString:@""]) {
Expand Down Expand Up @@ -6103,6 +6113,10 @@ - (void)_copyDatabase
}
#endif

/**
*
* This method *MUST* be called from the UI thread!
*/
- (void)_renameDatabase
{
NSString *newDatabaseName = [databaseRenameNameField stringValue];
Expand Down Expand Up @@ -6147,6 +6161,8 @@ - (void)_renameDatabase

/**
* Adds a new database.
*
* This method *MUST* be called from the UI thread!
*/
- (void)_addDatabase
{
Expand Down Expand Up @@ -6217,6 +6233,8 @@ - (void)_alterDatabase

/**
* Removes the current database.
*
* This method *MUST* be called from the UI thread!
*/
- (void)_removeDatabase
{
Expand Down

0 comments on commit 5a201e6

Please sign in to comment.