Skip to content

Commit

Permalink
Merge pull request #1371 from ychin/no-exception-when-quitting
Browse files Browse the repository at this point in the history
Don't throw Objective C exception when quitting MacVim
  • Loading branch information
ychin authored Feb 22, 2023
2 parents 1ec231d + 0c93e18 commit b17184f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,15 @@ - (void)applicationWillTerminate:(NSNotification *)notification
andEventID:'MOD '];
#endif

// We are hard shutting down the app here by terminating all Vim processes
// and then just quit without cleanly removing each Vim controller. We
// don't want the straggler controllers to still interact with the now
// invalid connections, so we just mark them as uninitialized.
for (NSUInteger i = 0, count = [vimControllers count]; i < count; ++i) {
MMVimController *vc = [vimControllers objectAtIndex:i];
[vc uninitialize];
}

// This will invalidate all connections (since they were spawned from this
// connection).
[connection invalidate];
Expand Down
1 change: 1 addition & 0 deletions src/MacVim/MMVimController.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
}

- (id)initWithBackend:(id)backend pid:(int)processIdentifier;
- (void)uninitialize;
- (unsigned)vimControllerId;
- (id)backendProxy;
- (int)pid;
Expand Down
9 changes: 9 additions & 0 deletions src/MacVim/MMVimController.m
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ - (void)dealloc
[super dealloc];
}

/// This should only be called by MMAppController when it's doing an app quit.
/// We just wait for all Vim processes to terminate instad of individually
/// closing each MMVimController. We simply unset isInitialized to prevent it
/// from handling and sending messages to now invalid Vim connections.
- (void)uninitialize
{
isInitialized = NO;
}

- (unsigned)vimControllerId
{
return identifier;
Expand Down

0 comments on commit b17184f

Please sign in to comment.