From 5a201e6cf26b26c6fd3dfab9cb18211e75bada26 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 31 Mar 2017 02:32:13 +0200 Subject: =?UTF-8?q?Fix=20a=20case=20of=20=E2=80=9Ebackground=20thread=20up?= =?UTF-8?q?dating=20UI=E2=80=9C=20that=20could=20cause=20an=20exception=20?= =?UTF-8?q?with=20a=20very=20specific=20timing=20(#2754)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPCustomQuery.m | 2 +- Source/SPDataImport.m | 4 ++-- Source/SPDatabaseDocument.m | 46 +++++++++++++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 17 deletions(-) (limited to 'Source') diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 6f79948d..591bcb12 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -802,7 +802,7 @@ // 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 diff --git a/Source/SPDataImport.m b/Source/SPDataImport.m index 03b83c6c..058ff916 100644 --- a/Source/SPDataImport.m +++ b/Source/SPDataImport.m @@ -690,10 +690,10 @@ } // 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]; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index bc1acb22..5338d2f7 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -410,6 +410,10 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; #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 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; /** * sets up the database select toolbar item + * + * This method *MUST* be called from the UI thread! */ - (IBAction)setDatabases:(id)sender; { @@ -1171,6 +1177,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; /** * Reset the current selected database name + * + * This method MAY be called from UI and background threads! */ - (void)refreshCurrentDatabase { @@ -1188,23 +1196,21 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; 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 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; #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 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; } #endif +/** + * + * This method *MUST* be called from the UI thread! + */ - (void)_renameDatabase { NSString *newDatabaseName = [databaseRenameNameField stringValue]; @@ -6147,6 +6161,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; /** * Adds a new database. + * + * This method *MUST* be called from the UI thread! */ - (void)_addDatabase { @@ -6217,6 +6233,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; /** * Removes the current database. + * + * This method *MUST* be called from the UI thread! */ - (void)_removeDatabase { -- cgit v1.2.3