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. --- backend.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'backend.go') diff --git a/backend.go b/backend.go index dd34fcc..fb9a3d1 100644 --- a/backend.go +++ b/backend.go @@ -7,7 +7,7 @@ import ( type Backend interface { Play(song *Song, player Player) - Search(map[string]string) []Song + Search(map[string]string) []*Song OnSongFinished(song *Song) } @@ -15,12 +15,12 @@ type DummyBackend struct{} func (dummy *DummyBackend) Play(song *Song, player Player) {} func (dummy *DummyBackend) OnSongFinished(song *Song) {} -func (dummy *DummyBackend) Search(map[string]string) []Song { +func (dummy *DummyBackend) Search(map[string]string) []*Song { s := NewDummySong("Dummy Mc Crashtest", "foo") - return []Song{s} + return []*Song{s} } -func NewDummySong(title, artist string) Song { +func NewDummySong(title, artist string) *Song { h := sha1.New() h.Write([]byte(title)) h.Write([]byte(artist)) -- cgit v1.2.3