Skip to content

Commit

Permalink
Fix out of bounds panic
Browse files Browse the repository at this point in the history
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: plietar#71
  • Loading branch information
joerg-krause committed Aug 23, 2016
1 parent cf7378f commit 0716643
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0716643

Please sign in to comment.