aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2017-03-31 02:32:13 +0200
committerMax <post@wickenrode.com>2017-03-31 02:32:13 +0200
commit5a201e6cf26b26c6fd3dfab9cb18211e75bada26 (patch)
tree546a530266dcc9f7af6a737df80a49c5ed1466cc
parent64929b3d810d8c18367ba869cba726f2360978d1 (diff)
downloadsequelpro-5a201e6cf26b26c6fd3dfab9cb18211e75bada26.tar.gz
sequelpro-5a201e6cf26b26c6fd3dfab9cb18211e75bada26.tar.bz2
sequelpro-5a201e6cf26b26c6fd3dfab9cb18211e75bada26.zip
Fix a case of „background thread updating UI“ that could cause an exception with a very specific timing (#2754)
-rw-r--r--Source/SPCustomQuery.m2
-rw-r--r--Source/SPDataImport.m4
-rw-r--r--Source/SPDatabaseDocument.m46
3 files changed, 35 insertions, 17 deletions
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
{