Permalink
Browse files

Fix a case of „background thread updating UI“ that could cause an exc…

…eption with a very specific timing (#2754)
  • Loading branch information...
dmoagx committed Mar 31, 2017
1 parent 64929b3 commit 5a201e6cf26b26c6fd3dfab9cb18211e75bada26
Showing with 35 additions and 17 deletions.
  1. +1 −1 Source/SPCustomQuery.m
  2. +2 −2 Source/SPDataImport.m
  3. +32 −14 Source/SPDatabaseDocument.m
View
@@ -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
View
@@ -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];
@@ -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]) {
@@ -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;
{
@@ -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
{
@@ -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
@@ -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:@""]) {
@@ -6103,6 +6113,10 @@ - (void)_copyDatabase
}
#endif
/**
*
* This method *MUST* be called from the UI thread!
*/
- (void)_renameDatabase
{
NSString *newDatabaseName = [databaseRenameNameField stringValue];
@@ -6147,6 +6161,8 @@ - (void)_renameDatabase
/**
* Adds a new database.
*
* This method *MUST* be called from the UI thread!
*/
- (void)_addDatabase
{
@@ -6217,6 +6233,8 @@ - (void)_alterDatabase
/**
* Removes the current database.
*
* This method *MUST* be called from the UI thread!
*/
- (void)_removeDatabase
{

0 comments on commit 5a201e6

Please sign in to comment.