From 26f0033ebb5f8e7c204a042709e3dfa885eac868 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 22 Jul 2023 15:15:47 +0200 Subject: fix applyTimeBonus by always using Song pointers Storing song objects in the Songs slice and using pointers to the underlying array slots breaks if the underlying array must be grown. When the array is grown the objects are copied to the new array and the pointers used in queue point to the old objects. This causes that Playlist.applyTimeBonus may not correctly apply to the most recent list of songs. This is fixed by always using Song pointers. --- playlist.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'playlist.go') diff --git a/playlist.go b/playlist.go index aeb1297..cb9c90c 100644 --- a/playlist.go +++ b/playlist.go @@ -78,7 +78,8 @@ func (pl *Playlist) OrderedList() []*Song { func (pl *Playlist) applyTimeBonus(timeBonus float64) { for _, s := range *pl { s.Weight += timeBonus + llog.DDebug("%p %v", s, s.Weight) } heap.Init(pl) - llog.DDebug("applying time bonus to the playlist") + llog.DDebug("applying time bonus to the playlist %v", *pl) } -- cgit v1.2.3