Skip to content

Commit 0fe5504

Browse files
committed
Fix playlist shuffle, index upper bound off-by-one
This caused projectM to sometimes stop switching presets if the index chosen was the end of the given interval. Since the preset switch fails in this case, no additional switches will happen unless the user manually switches to a new preset. Signed-off-by: Kai Blaschke <[email protected]>
1 parent e172add commit 0fe5504

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/playlist/Playlist.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ auto Playlist::NextPresetIndex() -> uint32_t
220220

221221
if (m_shuffle)
222222
{
223-
std::uniform_int_distribution<uint32_t> randomDistribution(0, static_cast<uint32_t>(m_items.size()));
223+
std::uniform_int_distribution<uint32_t> randomDistribution(0, static_cast<uint32_t>(m_items.size() - 1));
224224
m_currentPosition = randomDistribution(m_randomGenerator);
225225
}
226226
else
@@ -247,7 +247,7 @@ auto Playlist::PreviousPresetIndex() -> uint32_t
247247

248248
if (m_shuffle)
249249
{
250-
std::uniform_int_distribution<uint32_t> randomDistribution(0, static_cast<uint32_t>(m_items.size()));
250+
std::uniform_int_distribution<uint32_t> randomDistribution(0, static_cast<uint32_t>(m_items.size() - 1));
251251
m_currentPosition = randomDistribution(m_randomGenerator);
252252
}
253253
else

0 commit comments

Comments
 (0)