From 0d848aecbd40565f5030c3e4b2f859b92f59a2c2 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 2 Jun 2024 08:46:07 -0700 Subject: [PATCH] don't crash with index out of range when removing radios from saved play queue --- backend/app.go | 2 +- backend/savedplayqueue.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/app.go b/backend/app.go index 4a3cca4..31a8970 100644 --- a/backend/app.go +++ b/backend/app.go @@ -378,7 +378,7 @@ func (a *App) LoadSavedPlayQueue() error { if err := a.PlaybackManager.LoadTracks(queue.Tracks, Replace, false); err != nil { return err } - if queue.TrackIndex >= 0 { + if queue.TrackIndex >= 0 && queue.TrackIndex < len(queue.Tracks) { // TODO: This isn't ideal but doesn't seem to cause an audible play-for-a-split-second artifact a.PlaybackManager.PlayTrackAt(queue.TrackIndex) a.PlaybackManager.Pause() diff --git a/backend/savedplayqueue.go b/backend/savedplayqueue.go index 62a944f..fd6e025 100644 --- a/backend/savedplayqueue.go +++ b/backend/savedplayqueue.go @@ -36,6 +36,13 @@ func SavePlayQueue(serverID string, pm *PlaybackManager, filepath string, server trackIDs = append(trackIDs, item.Metadata().ID) } } + if l := len(trackIDs); trackIdx >= l { + if l == 0 { + trackIdx = 0 + } else { + trackIdx = l - 1 + } + } saved := serializedSavedPlayQueue{ ServerID: serverID,