[vlc-commits] [Git][videolan/vlc][master] macosx: Clear out old observers before creating new ones

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Sun Jun 7 16:53:34 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
2476eb53 by Claudio Cambra at 2026-06-07T18:42:57+02:00
macosx: Clear out old observers before creating new ones

Avoids crash when attempting to re-create observers for same paths
Can happen when reconfiguring media folders

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


1 changed file:

- modules/gui/macosx/library/VLCLibraryModel.m


Changes:

=====================================
modules/gui/macosx/library/VLCLibraryModel.m
=====================================
@@ -910,25 +910,33 @@ static void libraryCallback(void *p_data, const vlc_ml_event_t *p_event)
 
         NSMutableArray * const mutableArray =
             [[NSMutableArray alloc] initWithCapacity:pp_entrypoints->i_nb_items];
-        NSMutableArray * const mutableObservers =
-            [[NSMutableArray alloc] initWithCapacity:pp_entrypoints->i_nb_items];
 
         for (size_t x = 0; x < pp_entrypoints->i_nb_items; x++) {
             VLCMediaLibraryEntryPoint * const entryPoint =
                 [[VLCMediaLibraryEntryPoint alloc] initWithEntryPoint:&pp_entrypoints->p_items[x]];
             if (entryPoint) {
                 [mutableArray addObject:entryPoint];
-
-                NSURL * const url = [NSURL URLWithString:entryPoint.MRL];
-                VLCMediaLibraryFolderObserver * const observer =
-                    [[VLCMediaLibraryFolderObserver alloc] initWithURL:url];
-                [mutableObservers addObject:observer];
             }
         }
 
         vlc_ml_folder_list_release(pp_entrypoints);
 
         dispatch_async(dispatch_get_main_queue(), ^{
+            // Stop old observers before creating new ones to avoid duplicate
+            // FSEvent streams for the same paths
+            self.folderObservers = nil;
+
+            NSMutableArray * const mutableObservers =
+                [[NSMutableArray alloc] initWithCapacity:mutableArray.count];
+            for (VLCMediaLibraryEntryPoint * const entryPoint in mutableArray) {
+                NSURL * const url = [NSURL URLWithString:entryPoint.MRL];
+                VLCMediaLibraryFolderObserver * const observer =
+                    [[VLCMediaLibraryFolderObserver alloc] initWithURL:url];
+                if (observer) {
+                    [mutableObservers addObject:observer];
+                }
+            }
+
             self.cachedListOfMonitoredFolders = mutableArray.copy;
             self.folderObservers = mutableObservers.copy;
             [self.changeDelegate notifyChange:VLCLibraryModelListOfMonitoredFoldersUpdated withObject:self];



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2476eb53e76d650fbd85fc79f301637a600353c3

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2476eb53e76d650fbd85fc79f301637a600353c3
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list