Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
434c3fc6 by Serhii Bykov at 2026-03-03T11:23:54+00:00
macosx: Fix collection view crashes from inconsistent data in
VLCLibraryAudioGroupDataSource
- - - - -
1 changed file:
- modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.m
Changes:
=====================================
modules/gui/macosx/library/audio-library/VLCLibraryAudioGroupDataSource.m
=====================================
@@ -138,9 +138,15 @@
}];
}
-- (void)handleAlbumUpdateInRow:(NSInteger)row
+- (void)handleAlbumUpdate:(VLCMediaLibraryAlbum *)album inRow:(NSInteger)row
{
+ NSParameterAssert(album != nil);
NSParameterAssert(row >= 0 && (NSUInteger)row <
self.representedListOfAlbums.count);
+
+ NSMutableArray * const mutableCopy = [self.representedListOfAlbums
mutableCopy];
+ [mutableCopy replaceObjectAtIndex:row withObject:album];
+ self.representedListOfAlbums = [mutableCopy copy];
+
NSIndexSet * const indexSet = [NSIndexSet indexSetWithIndex:row];
NSIndexSet * const columnIndexSet = [NSIndexSet indexSetWithIndex:0];
NSSet * const indexPaths = [NSSet setWithObject:[NSIndexPath
indexPathForItem:row inSection:0]];
@@ -156,11 +162,18 @@
{
NSParameterAssert(item != nil);
const NSInteger row = [self rowContainingMediaItem:item];
- if (row == NSNotFound) {
+ if (row == NSNotFound || row < 0 || (NSUInteger)row >=
self.representedListOfAlbums.count) {
NSLog(@"VLCLibraryAudioGroupDataSource: Unable to find row for library
item, can't change");
return;
}
- [self handleAlbumUpdateInRow:row];
+
+ VLCMediaLibraryAlbum * const existingAlbum =
self.representedListOfAlbums[row];
+ VLCMediaLibraryAlbum * const refreshedAlbum = [VLCMediaLibraryAlbum
albumWithID:existingAlbum.libraryID];
+ if (refreshedAlbum == nil) {
+ return;
+ }
+
+ [self handleAlbumUpdate:refreshedAlbum inRow:row];
}
- (void)performActionOnTableViews:(void (^)(NSTableView *))tableViewAction
@@ -192,7 +205,7 @@
- (void)libraryModelAudioMediaItemDeleted:(NSNotification *)notification
{
- [self handleLibraryItemChange:notification.object];
+ [self updateRepresentedListOfAlbums];
}
- (void)libraryModelAlbumsReset:(NSNotification *)notification
@@ -202,23 +215,27 @@
- (void)libraryModelAlbumUpdated:(NSNotification *)notification
{
- const NSInteger row = [self rowForLibraryItem:notification.object];
+ VLCMediaLibraryAlbum * const album = (VLCMediaLibraryAlbum
*)notification.object;
+ const NSInteger row = [self rowForLibraryItem:album];
if (row == NSNotFound) {
NSLog(@"VLCLibraryAudioGroupDataSource: Unable to find row for library
item, can't update");
return;
}
- [self handleAlbumUpdateInRow:row];
+ [self handleAlbumUpdate:album inRow:row];
}
- (void)libraryModelAlbumDeleted:(NSNotification *)notification
{
const NSInteger row = [self rowForLibraryItem:notification.object];
if (row == NSNotFound) {
- NSLog(@"VLCLibraryAudioGroupDataSource: Unable to find row for library
item, can't delete");
return;
}
+ NSMutableArray * const mutableCopy = [self.representedListOfAlbums
mutableCopy];
+ [mutableCopy removeObjectAtIndex:row];
+ self.representedListOfAlbums = [mutableCopy copy];
+
NSIndexSet * const indexSet = [NSIndexSet indexSetWithIndex:row];
NSSet * const indexPaths = [NSSet setWithObject:[NSIndexPath
indexPathForItem:row inSection:0]];
@@ -259,17 +276,18 @@
{
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
VLCLibraryModel * const libraryModel =
VLCMain.sharedInstance.libraryController.libraryModel;
+ NSArray<VLCMediaLibraryAlbum *> *albums;
+
if (self.representedAudioGroup == nil || self.currentParentType ==
VLCMediaLibraryParentGroupTypeUnknown) {
- self.representedListOfAlbums = libraryModel.listOfAlbums;
+ albums = libraryModel.listOfAlbums;
} else if (self.representedAudioGroup.albums.count == 0) {
- dispatch_sync(dispatch_get_main_queue(), ^{
- self.representedListOfAlbums = [libraryModel
listAlbumsOfParentType:self.currentParentType
forID:self.representedAudioGroup.libraryID];
- });
+ albums = [libraryModel
listAlbumsOfParentType:self.currentParentType
forID:self.representedAudioGroup.libraryID];
} else {
- self.representedListOfAlbums = self.representedAudioGroup.albums;
+ albums = self.representedAudioGroup.albums;
}
dispatch_async(dispatch_get_main_queue(), ^{
+ self.representedListOfAlbums = albums;
[self reloadData];
});
});
@@ -400,9 +418,9 @@
viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
- (id<VLCMediaLibraryItemProtocol>)libraryItemAtIndexPath:(NSIndexPath
*)indexPath
forCollectionView:(NSCollectionView
*)collectionView
{
- const NSUInteger indexPathItem = indexPath.item;
+ const NSInteger indexPathItem = indexPath.item;
- if (indexPathItem < 0 || indexPathItem >=
self.representedListOfAlbums.count) {
+ if (indexPathItem < 0 || (NSUInteger)indexPathItem >=
self.representedListOfAlbums.count) {
return nil;
}
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/commit/434c3fc69f722bd17803908daf8e80c0a5c02dc5
--
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/commit/434c3fc69f722bd17803908daf8e80c0a5c02dc5
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits