From 4d38d4f9ee46f3de9e16374bbdce563b385b8e7f Mon Sep 17 00:00:00 2001 From: casey Date: Mon, 13 Jun 2016 16:42:57 -0700 Subject: [PATCH] Added some boundry checking to BrowseLayout and PlaybackService, which should fix the empty library crash. --- src/musikbox/app/layout/BrowseLayout.cpp | 12 ++++++++---- src/musikbox/app/service/PlaybackService.cpp | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/musikbox/app/layout/BrowseLayout.cpp b/src/musikbox/app/layout/BrowseLayout.cpp index 09a3f4b9b..f8d365843 100755 --- a/src/musikbox/app/layout/BrowseLayout.cpp +++ b/src/musikbox/app/layout/BrowseLayout.cpp @@ -142,12 +142,16 @@ void BrowseLayout::OnCategoryViewInvalidated( bool BrowseLayout::KeyPress(const std::string& key) { if (key == "^M") { /* enter. play the selection */ auto tracks = this->trackList->GetTrackList(); - auto focus = this->GetFocus(); - size_t index = (focus == this->trackList) - ? this->trackList->GetSelectedIndex() : 0; + if (tracks && tracks->size()) { + auto focus = this->GetFocus(); + + size_t index = (focus == this->trackList) + ? this->trackList->GetSelectedIndex() : 0; + + this->playback.Play(*tracks, index); + } - this->playback.Play(*tracks, index); return true; } if (key == "KEY_F(5)") { diff --git a/src/musikbox/app/service/PlaybackService.cpp b/src/musikbox/app/service/PlaybackService.cpp index 5d84286d0..356c80b82 100755 --- a/src/musikbox/app/service/PlaybackService.cpp +++ b/src/musikbox/app/service/PlaybackService.cpp @@ -137,7 +137,9 @@ void PlaybackService::Play(std::vector& tracks, size_t index) { std::swap(temp, this->playlist); } - this->Play(index); + if (index <= tracks.size()) { + this->Play(index); + } } void PlaybackService::Copy(std::vector& target) {