From 0716643ae33f341c18b9efaebb8295e2cbdd52a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Krause?= Date: Tue, 23 Aug 2016 23:43:55 +0200 Subject: [PATCH] Fix out of bounds panic Selecting a librespot device with the Spotify desktop client causes a crash if the playlist is empty. Take into account the case where an empty list of tracks is received. In this case notify the desktop client, so it will accept the device and turn the status bar green. Closes: #71 --- src/spirc.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/spirc.rs b/src/spirc.rs index 969ed3ff..e2bea2a8 100644 --- a/src/spirc.rs +++ b/src/spirc.rs @@ -209,11 +209,14 @@ impl SpircInternal { } self.reload_tracks(&frame); - - let play = frame.get_state().get_status() == PlayStatus::kPlayStatusPlay; - let track = self.tracks[self.index as usize]; - let position = frame.get_state().get_position_ms(); - self.player.load(track, play, position); + if self.tracks.len() > 0 { + let play = frame.get_state().get_status() == PlayStatus::kPlayStatusPlay; + let track = self.tracks[self.index as usize]; + let position = frame.get_state().get_position_ms(); + self.player.load(track, play, position); + } else { + self.notify(false, Some(frame.get_ident())); + } } MessageType::kMessageTypePlay => { self.player.play();