Permalink
Browse files

Attempt to fix #1961

Namely this commit changes two things:
1) In the past the user manager window technically was closed after it was released (SPUserManager.m:491):

    [NSApp endSheet:[self window] returnCode:0]; //-> calls delegate,  which calls release
    [[self window] orderOut:self];

This call order has now been swapped.
2) Because the delegate is invoked directly by NSApp, the release was called before other UI elements had finished their cleanup from orderOut:. The delegate callback is now put on the runloop to give other stuff priority.

Requesting QA on this commit.
  • Loading branch information...
dmoagx committed Nov 11, 2014
1 parent 6d48720 commit 69ca4afe9ba4c9c710b69e4d22d32d22a007c8a9
Showing with 38 additions and 13 deletions.
  1. +0 −1 Source/SPDatabaseDocument.h
  2. +4 −10 Source/SPDatabaseDocument.m
  3. +8 −0 Source/SPUserManager.h
  4. +26 −2 Source/SPUserManager.m
@@ -427,7 +427,6 @@
- (void)saveConnectionPanelDidEnd:(NSSavePanel *)panel returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (BOOL)saveDocumentWithFilePath:(NSString *)fileName inBackground:(BOOL)saveInBackground onlyPreferences:(BOOL)saveOnlyPreferences contextInfo:(NSDictionary*)contextInfo;
- (void)userManagerSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void*)context;
- (void)setIsSavedInBundle:(BOOL)savedInBundle;
- (void)setFileURL:(NSURL *)fileURL;
- (void)connect;
@@ -2483,16 +2483,10 @@ - (IBAction)showUserManager:(id)sender
return;
}
[NSApp beginSheet:[userManagerInstance window]
modalForWindow:parentWindow
modalDelegate:self
didEndSelector:@selector(userManagerSheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
- (void)userManagerSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void*)context
{
[userManagerInstance release], userManagerInstance = nil;
[userManagerInstance beginSheetModalForWindow:parentWindow
completionHandler:^(){
[userManagerInstance release], userManagerInstance = nil;
}];
}
/**
@@ -124,4 +124,12 @@
- (BOOL)grantPrivilegesToUser:(NSManagedObject *)user;
- (BOOL)grantDbPrivilegesWithPrivilege:(NSManagedObject *)user;
// External
/**
* Display the user manager as a sheet attached to a chosen window
* @param docWindow The parent window.
* @param callback A callback that will be called once the window is closed again. Can be NULL.
*/
- (void)beginSheetModalForWindow:(NSWindow *)docWindow completionHandler:(void (^)())callback;
@end
@@ -61,6 +61,7 @@ - (NSArray *)_fetchPrivsWithUser:(NSString *)username schema:(NSString *)selecte
- (void)_setSchemaPrivValues:(NSArray *)objects enabled:(BOOL)enabled;
- (void)_initializeAvailablePrivs;
- (void)_renameUserFrom:(NSString *)originalUser host:(NSString *)originalHost to:(NSString *)newUser host:(NSString *)newHost;
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void*)context;
@end
@@ -471,6 +472,31 @@ - (NSManagedObjectContext *)managedObjectContext
return managedObjectContext;
}
- (void)beginSheetModalForWindow:(NSWindow *)docWindow completionHandler:(void (^)())callback
{
//copy block from stack to heap, otherwise it wouldn't live long enough to be invoked later.
void *heapCallback = callback? Block_copy(callback) : NULL;
[NSApp beginSheet:[self window]
modalForWindow:docWindow
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:heapCallback];
}
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void*)context
{
//[NSApp endSheet...] does not close the window
[[self window] orderOut:self];
//notify delegate
if(context) {
void (^callback)() = context;
//directly invoking callback would risk that we are dealloc'd while still in this run loop iteration.
dispatch_async(dispatch_get_main_queue(), callback);
Block_release(callback);
}
}
#pragma mark -
#pragma mark General IBAction methods
@@ -489,7 +515,6 @@ - (IBAction)doCancel:(id)sender
// Close sheet
[NSApp endSheet:[self window] returnCode:0];
[[self window] orderOut:self];
}
/**
@@ -539,7 +564,6 @@ - (IBAction)doApply:(id)sender
// Otherwise, close the sheet
[NSApp endSheet:[self window] returnCode:0];
[[self window] orderOut:self];
}
/**

0 comments on commit 69ca4af

Please sign in to comment.