[vlc-commits] macosx: remove unnecessary deinitialize calls (fixes #21914)

Felix Paul Kühne git at videolan.org
Mon Apr 29 19:26:59 CEST 2019


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sat Apr 27 19:49:44 2019 +0200| [66c49cf911d2b548ff1112d885ebddfd743f8dab] | committer: Felix Paul Kühne

macosx: remove unnecessary deinitialize calls (fixes #21914)

The macOS interface is deallocated after the player/playlist, so we need to unsubscribe from either as soon as we know that the app will terminate.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=66c49cf911d2b548ff1112d885ebddfd743f8dab
---

 modules/gui/macosx/main/VLCMain.m                   |  8 --------
 modules/gui/macosx/playlist/VLCPlayerController.h   |  1 -
 modules/gui/macosx/playlist/VLCPlayerController.m   | 11 ++++++++++-
 modules/gui/macosx/playlist/VLCPlaylistController.h |  1 -
 modules/gui/macosx/playlist/VLCPlaylistController.m | 15 ++++++++++-----
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/modules/gui/macosx/main/VLCMain.m b/modules/gui/macosx/main/VLCMain.m
index a141edaef7..06e67967b3 100644
--- a/modules/gui/macosx/main/VLCMain.m
+++ b/modules/gui/macosx/main/VLCMain.m
@@ -295,14 +295,6 @@ static VLCMain *sharedInstance = nil;
     return self;
 }
 
-- (void)dealloc
-{
-    msg_Dbg(getIntf(), "Deinitializing VLCMain object");
-
-    /* have the playlist controller explicitly unsubscribe from events prior to its deallocation */
-    [_playlistController deinitialize];
-}
-
 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
 {
     _clickerManager = [[VLCClickerManager alloc] init];
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.h b/modules/gui/macosx/playlist/VLCPlayerController.h
index ea06f81482..711f59e5dd 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.h
+++ b/modules/gui/macosx/playlist/VLCPlayerController.h
@@ -230,7 +230,6 @@ extern NSString *VLCPlayerMuteChanged;
 @interface VLCPlayerController : NSObject
 
 - (instancetype)initWithPlayer:(vlc_player_t *)player;
-- (void)deinitialize;
 
 /**
  * Start playback of the current media
diff --git a/modules/gui/macosx/playlist/VLCPlayerController.m b/modules/gui/macosx/playlist/VLCPlayerController.m
index 49833a538c..d6526f25d1 100644
--- a/modules/gui/macosx/playlist/VLCPlayerController.m
+++ b/modules/gui/macosx/playlist/VLCPlayerController.m
@@ -533,6 +533,10 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
     self = [super init];
     if (self) {
         _defaultNotificationCenter = [NSNotificationCenter defaultCenter];
+        [_defaultNotificationCenter addObserver:self
+                                       selector:@selector(applicationWillTerminate:)
+                                           name:NSApplicationWillTerminateNotification
+                                         object:nil];
         _position = -1.f;
         _time = VLC_TICK_INVALID;
         _p_player = player;
@@ -557,7 +561,7 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
     return self;
 }
 
-- (void)deinitialize
+- (void)applicationWillTerminate:(NSNotification *)aNotification
 {
     [self onPlaybackHasTruelyEnded:nil];
     if (@available(macOS 10.12.2, *)) {
@@ -581,6 +585,11 @@ static const struct vlc_player_aout_cbs player_aout_callbacks = {
     }
 }
 
+- (void)dealloc
+{
+    [_defaultNotificationCenter removeObserver:self];
+}
+
 #pragma mark - playback control methods
 
 - (int)start
diff --git a/modules/gui/macosx/playlist/VLCPlaylistController.h b/modules/gui/macosx/playlist/VLCPlaylistController.h
index 639e5f2459..908aaafa5a 100644
--- a/modules/gui/macosx/playlist/VLCPlaylistController.h
+++ b/modules/gui/macosx/playlist/VLCPlaylistController.h
@@ -41,7 +41,6 @@ extern NSString *VLCPlaylistItemsRemoved;
 @interface VLCPlaylistController : NSObject
 
 - (instancetype)initWithPlaylist:(vlc_playlist_t *)playlist;
-- (void)deinitialize;
 
 /**
  * The vlc core playlist controlled by the instance of this class
diff --git a/modules/gui/macosx/playlist/VLCPlaylistController.m b/modules/gui/macosx/playlist/VLCPlaylistController.m
index 49b05714da..5b90df74c5 100644
--- a/modules/gui/macosx/playlist/VLCPlaylistController.m
+++ b/modules/gui/macosx/playlist/VLCPlaylistController.m
@@ -201,6 +201,10 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     self = [super init];
     if (self) {
         _defaultNotificationCenter = [NSNotificationCenter defaultCenter];
+        [_defaultNotificationCenter addObserver:self
+                                       selector:@selector(applicationWillTerminate:)
+                                           name:NSApplicationWillTerminateNotification
+                                         object:nil];
         _p_playlist = playlist;
 
         /* set initial values, further updates through callbacks */
@@ -219,12 +223,8 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     return self;
 }
 
-- (void)deinitialize
+- (void)applicationWillTerminate:(NSNotification *)aNotification
 {
-    if (_playerController) {
-        [_playerController deinitialize];
-    }
-
     if (_p_playlist) {
         if (_playlistListenerID) {
             vlc_playlist_Lock(_p_playlist);
@@ -234,6 +234,11 @@ static const struct vlc_playlist_callbacks playlist_callbacks = {
     }
 }
 
+- (void)dealloc
+{
+    [_defaultNotificationCenter removeObserver:self];
+}
+
 #pragma mark - callback forwarders
 
 - (void)playlistResetWithItems:(NSArray *)items



More information about the vlc-commits mailing list