From 87259920e8496081001b501d6448eba9acee0ed8 Mon Sep 17 00:00:00 2001 From: Daniel Barber Date: Fri, 14 Feb 2020 16:29:30 -0500 Subject: [PATCH] Attempt to fix album detail view crash Very occasionally the album detail view fails to get the album tracks and this causes a crash. This extra guard avoids the crash, but doesn't fix the underlying problem. The problem itself is very hard to track down because it's incredibly hard to reproduce. --- .../Browser/Album Detail/AlbumDetailView.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Persephone/Components/Browser/Album Detail/AlbumDetailView.swift b/Persephone/Components/Browser/Album Detail/AlbumDetailView.swift index 9f3a9a9..1668a10 100644 --- a/Persephone/Components/Browser/Album Detail/AlbumDetailView.swift +++ b/Persephone/Components/Browser/Album Detail/AlbumDetailView.swift @@ -113,15 +113,18 @@ class AlbumDetailView: NSViewController { } func getAlbumSongs(for album: Album) { - App.mpdClient.getAlbumSongs(for: album.mpdAlbum) { [self] (mpdSongs: [MPDClient.MPDSong]) in - self.dataSource.setAlbumSongs( - mpdSongs.map { Song(mpdSong: $0) } - ) + App.mpdClient.getAlbumSongs(for: album.mpdAlbum) { [weak self] (mpdSongs: [MPDClient.MPDSong]) in + guard let self = self else { return } DispatchQueue.main.async { + self.dataSource.setAlbumSongs( + mpdSongs.map { Song(mpdSong: $0) } + ) + self.albumTracksView.reloadData() - guard let song = self.dataSource.albumSongs.first?.song ?? + guard !self.dataSource.albumSongs.isEmpty, + let song = self.dataSource.albumSongs.first?.song ?? self.dataSource.albumSongs[1].song else { return }