Skip to content

Commit eccdd26

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 2fd65e8 commit eccdd26

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
@@ -253,7 +253,7 @@ auto Playlist::NextPresetIndex() -> uint32_t
253253

254254
if (m_shuffle)
255255
{
256-
std::uniform_int_distribution<uint32_t> randomDistribution(0, static_cast<uint32_t>(m_items.size()));
256+
std::uniform_int_distribution<uint32_t> randomDistribution(0, static_cast<uint32_t>(m_items.size() - 1));
257257
m_currentPosition = randomDistribution(m_randomGenerator);
258258
}
259259
else
@@ -280,7 +280,7 @@ auto Playlist::PreviousPresetIndex() -> uint32_t
280280

281281
if (m_shuffle)
282282
{
283-
std::uniform_int_distribution<uint32_t> randomDistribution(0, static_cast<uint32_t>(m_items.size()));
283+
std::uniform_int_distribution<uint32_t> randomDistribution(0, static_cast<uint32_t>(m_items.size() - 1));
284284
m_currentPosition = randomDistribution(m_randomGenerator);
285285
}
286286
else

0 commit comments

Comments
 (0)