From 6e76c79e0afbbcf2dbeb9db21a0dbfa4612d3acb Mon Sep 17 00:00:00 2001 From: Jason Waataja Date: Fri, 20 Jul 2018 17:19:19 -0700 Subject: [PATCH] Fixed reset on non-empty queue Fixed an issue where reset didn't work when the queue had any tracks in it. The issue stemmed from the fact that in the last few lines of the PlayCurrent method in the queue.go, around line 314, it sets up another thread to wait and eventually skip the current track. When reset is called this skip is triggered on an empty queue which causes an error. Fixed it by adding a check around the offending lines. --- bot/queue.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bot/queue.go b/bot/queue.go index 505c967..a8f38dc 100644 --- a/bot/queue.go +++ b/bot/queue.go @@ -211,22 +211,24 @@ func (q *Queue) Skip() { } // Remove all playlist skips if this is the last track of the playlist still in the queue. - if playlist := q.Queue[0].GetPlaylist(); playlist != nil { - id := playlist.GetID() - playlistIsFinished := true + if len(q.Queue) > 0 { + if playlist := q.Queue[0].GetPlaylist(); playlist != nil { + id := playlist.GetID() + playlistIsFinished := true - q.mutex.Unlock() - q.Traverse(func(i int, t interfaces.Track) { - if i != 0 && t.GetPlaylist() != nil { - if t.GetPlaylist().GetID() == id { - playlistIsFinished = false + q.mutex.Unlock() + q.Traverse(func(i int, t interfaces.Track) { + if i != 0 && t.GetPlaylist() != nil { + if t.GetPlaylist().GetID() == id { + playlistIsFinished = false + } } - } - }) - q.mutex.Lock() + }) + q.mutex.Lock() - if playlistIsFinished { - DJ.Skips.ResetPlaylistSkips() + if playlistIsFinished { + DJ.Skips.ResetPlaylistSkips() + } } }