Skip to content

Commit 0c93e18

Browse files
committed
Don't throw Objective C exception when quitting MacVim
Currently when quitting MacVim, MMVimController will throw an exception in `sendMessage:`. This is because MMAppController's handler for quitting simply closes the connection, terminates the Vim processes and quit; it doesn't individually shut down each Vim controller cleanly. This is actually ok because we are quitting the app anyway, and it's not terrible to just let the OS clean up (applicationWillTerminate also has a 5 second executation timer set by macOS), but we do need to make sure Vim controllers won't be trying to handle the now invalid connections. Currently the exceptions will be caught by an exception handler, but it's still not great, and could be confused with a bug, especially if logging is enabled. Add a way to set `isInitialized` to NO when shutting down, so that the controllers will be blocked from trying to send connections.
1 parent 30f3dd4 commit 0c93e18

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/MacVim/MMAppController.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,15 @@ - (void)applicationWillTerminate:(NSNotification *)notification
759759
andEventID:'MOD '];
760760
#endif
761761

762+
// We are hard shutting down the app here by terminating all Vim processes
763+
// and then just quit without cleanly removing each Vim controller. We
764+
// don't want the straggler controllers to still interact with the now
765+
// invalid connections, so we just mark them as uninitialized.
766+
for (NSUInteger i = 0, count = [vimControllers count]; i < count; ++i) {
767+
MMVimController *vc = [vimControllers objectAtIndex:i];
768+
[vc uninitialize];
769+
}
770+
762771
// This will invalidate all connections (since they were spawned from this
763772
// connection).
764773
[connection invalidate];

src/MacVim/MMVimController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
}
5858

5959
- (id)initWithBackend:(id)backend pid:(int)processIdentifier;
60+
- (void)uninitialize;
6061
- (unsigned)vimControllerId;
6162
- (id)backendProxy;
6263
- (int)pid;

src/MacVim/MMVimController.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ - (void)dealloc
248248
[super dealloc];
249249
}
250250

251+
/// This should only be called by MMAppController when it's doing an app quit.
252+
/// We just wait for all Vim processes to terminate instad of individually
253+
/// closing each MMVimController. We simply unset isInitialized to prevent it
254+
/// from handling and sending messages to now invalid Vim connections.
255+
- (void)uninitialize
256+
{
257+
isInitialized = NO;
258+
}
259+
251260
- (unsigned)vimControllerId
252261
{
253262
return identifier;

0 commit comments

Comments
 (0)