diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 0d46c0e906..a354378777 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -375,7 +375,8 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) - (void)restartMediaKeys { - CGEventTapEnable(self->_mk_tap_port, true); + if (self->_mk_tap_port) + CGEventTapEnable(self->_mk_tap_port, true); } - (void)setHighestPriotityMediaKeysTap @@ -410,10 +411,10 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) tap_event_callback, self); - assert(self->_mk_tap_port != nil); - - NSMachPort *port = (NSMachPort *)self->_mk_tap_port; - [[NSRunLoop mainRunLoop] addPort:port forMode:NSRunLoopCommonModes]; + if (self->_mk_tap_port) { + NSMachPort *port = (NSMachPort *)self->_mk_tap_port; + [[NSRunLoop mainRunLoop] addPort:port forMode:NSRunLoopCommonModes]; + } }); } @@ -421,10 +422,12 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx) { dispatch_async(dispatch_get_main_queue(), ^{ NSMachPort *port = (NSMachPort *)self->_mk_tap_port; - CGEventTapEnable(self->_mk_tap_port, false); - [[NSRunLoop mainRunLoop] removePort:port forMode:NSRunLoopCommonModes]; - CFRelease(self->_mk_tap_port); - self->_mk_tap_port = nil; + if (port) { + CGEventTapEnable(self->_mk_tap_port, false); + [[NSRunLoop mainRunLoop] removePort:port forMode:NSRunLoopCommonModes]; + CFRelease(self->_mk_tap_port); + self->_mk_tap_port = nil; + } }); }