From 9bd819a0bc809ab5af300e5d73e88f120c5d0285 Mon Sep 17 00:00:00 2001 From: Akemi Date: Thu, 23 Feb 2017 01:37:23 +0100 Subject: cocoa: fix segfault in certain circumstances MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit i falsely assumed that the windowDidChangeScreen was meant to report ‘physical’ screen changes but was wondering why it triggers on other events too. it actually is a event that informs us when anything referenced by our current NSScreen is changed. even when something referenced in the NSScreen changed the old and new NSScreen are still equal if the physical screen didn’t change. with that my previous optimisation broke some cases where the physical screen didn’t change but things it referenced did, leading to a segfault when theses were accessed. to keep the optimisation we will always update our internal NSScreen reference but the rest only when the physical screen was changed. --- video/out/cocoa/mpvadapter.h | 1 + video/out/cocoa/window.m | 7 ++++--- video/out/cocoa_common.m | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/video/out/cocoa/mpvadapter.h b/video/out/cocoa/mpvadapter.h index 65832aeae5..b5fa8adbf4 100644 --- a/video/out/cocoa/mpvadapter.h +++ b/video/out/cocoa/mpvadapter.h @@ -28,6 +28,7 @@ - (void)handleFilesArray:(NSArray *)files; - (void)didChangeWindowedScreenProfile:(NSNotification *)notification; - (void)performAsyncResize:(NSSize)size; +- (void)windowDidChangePhysicalScreen; - (BOOL)isInFullScreenMode; - (BOOL)keyboardEnabled; diff --git a/video/out/cocoa/window.m b/video/out/cocoa/window.m index 028b17985f..88b1596d40 100644 --- a/video/out/cocoa/window.m +++ b/video/out/cocoa/window.m @@ -168,14 +168,15 @@ - (void)windowDidChangeScreen:(NSNotification *)notification { - //this event doesn't exclusively trigger on screen change - //examples: screen reconfigure, toggling fullscreen + [self.adapter windowDidChangeScreen:notification]; + if (!_is_animating && ![[self currentScreen] isEqual:[self screen]]) { self.previousScreen = [self screen]; } if (![[self currentScreen] isEqual:[self screen]]) { - [self.adapter windowDidChangeScreen:notification]; + [self.adapter windowDidChangePhysicalScreen]; } + self.currentScreen = [self screen]; } diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index f59ffd9005..e3f359eb5c 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -1018,6 +1018,10 @@ int vo_cocoa_control(struct vo *vo, int *events, int request, void *arg) - (void)windowDidChangeScreen:(NSNotification *)notification { vo_cocoa_update_screen_info(self.vout); +} + +- (void)windowDidChangePhysicalScreen +{ vo_cocoa_update_displaylink(self.vout); flag_events(self.vout, VO_EVENT_WIN_STATE); } -- cgit v1.2.3