[vlc-commits] [Git][videolan/vlc][master] macosx: only interact with main NSMenu from main thread

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Dec 1 20:54:12 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
b45800a5 by Marvin Scholz at 2023-12-01T20:34:11+00:00
macosx: only interact with main NSMenu from main thread

The main NSMenu must not be modified from any other thread that is not
the main thread.

Fixes an exception when adding renderer items on recent macOS versions.

- - - - -


1 changed file:

- modules/gui/macosx/menus/renderers/VLCRendererMenuController.m


Changes:

=====================================
modules/gui/macosx/menus/renderers/VLCRendererMenuController.m
=====================================
@@ -125,18 +125,24 @@
                    range:[unformattedTitle rangeOfString:item.userReadableType options:NSBackwardsSearch]];
     menuItem.attributedTitle = title;
 
-    [_rendererMenu insertItem:menuItem atIndex:[_rendererMenu indexOfItem:_rendererNoneItem] + 1];
+    // The main menu must only be updated from the main thread
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [_rendererMenu insertItem:menuItem atIndex:[_rendererMenu indexOfItem:_rendererNoneItem] + 1];
+    });
 }
 
 - (void)removeRendererItem:(VLCRendererItem *)item
 {
-    NSInteger index = [_rendererMenu indexOfItemWithRepresentedObject:item];
-    if (index >= 0) {
-        NSMenuItem *menuItem = [_rendererMenu itemAtIndex:index];
-        // Don't remove selected item
-        if (menuItem != _selectedItem)
-            [_rendererMenu removeItemAtIndex:index];
-    }
+    // The main menu must only be updated from the main thread
+    dispatch_async(dispatch_get_main_queue(), ^{
+        NSInteger index = [_rendererMenu indexOfItemWithRepresentedObject:item];
+        if (index >= 0) {
+            NSMenuItem *menuItem = [_rendererMenu itemAtIndex:index];
+            // Don't remove selected item
+            if (menuItem != _selectedItem)
+                [_rendererMenu removeItemAtIndex:index];
+        }
+    });
 }
 
 - (void)startRendererDiscoveries



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

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/b45800a5743f3ac4fde5bf0a22addf7c4a9eb65f
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list