Skip to content

Commit

Permalink
Fix #3: Crash on empty songlist page switching
Browse files Browse the repository at this point in the history
  • Loading branch information
v-atamanenko committed Apr 10, 2022
1 parent 8c5c89e commit 75aeca2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion source/Modes/SongSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,14 @@ void SongSelect::UpdateSonglist(bool initial)

OOUInt beatmap_list_offset = mCurrentPage * mEntriesPerPage;
OOUInt entries_on_page = mEntriesPerPage;
if (beatmap_list_offset + (entries_on_page-1) >= mSongListSize) {

if (entries_on_page >= mSongListSize) {
entries_on_page = mSongListSize;
beatmap_list_offset = 0;
mCurrentPage = 0;
}

if (entries_on_page != 0 && (beatmap_list_offset + (entries_on_page-1) >= mSongListSize)) {
entries_on_page = mSongListSize - beatmap_list_offset;
}

Expand Down
4 changes: 4 additions & 0 deletions source/Modes/SongSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SongSelect : public Mode

static void PageNext() {
AudioManager::Engine().PlayUISound(UISOUND_CLICK_SHORT_CONFIRM);
if (mCountPages == 0) { return; }
if (mCurrentPage < (mCountPages - 1)) {
PreviewBuffer::GetInstance().Update((OOInt)mCurrentPage, (mCurrentPage+1), mEntriesPerPage);
mCurrentPage++;
Expand All @@ -35,6 +36,7 @@ class SongSelect : public Mode
};
static void PagePrev() {
AudioManager::Engine().PlayUISound(UISOUND_CLICK_SHORT_CONFIRM);
if (mCountPages == 0) { return; }
if (mCurrentPage > 0) {
PreviewBuffer::GetInstance().Update((OOInt)mCurrentPage, (mCurrentPage-1), mEntriesPerPage);
mCurrentPage--;
Expand All @@ -44,6 +46,8 @@ class SongSelect : public Mode
};
static void PageRand() {
AudioManager::Engine().PlayUISound(UISOUND_CLICK_SHORT_CONFIRM);
if (mCountPages == 0) { return; }

if (mCountPages <= 1) {
shouldExpandRandomEntry = true;
return;
Expand Down

0 comments on commit 75aeca2

Please sign in to comment.