haskell-game / sdl2-mixer

Haskell bindings to SDL2_mixer.
BSD 3-Clause "New" or "Revised" License
12 stars 10 forks source link

load music considered harmful? #5

Open soupi opened 6 years ago

soupi commented 6 years ago

sorry for the generic title.

I just finished debugging an issue where I used load to read a music file from disk and play it. I also kept all the Music values I loaded in a Map. I ran into all kinds of strange bugs, music jumping forward at a specific place, trying to play music I already played wouldn't do anything after playing something else, music starting from the middle of the file, etc.

Then I thought that maybe the ByteString content of the file was garbage collected and/or overwritten or something. So instead of keeping a Map of Music I kept a Map of ByteString which is the result of readFile and I played music using playMusic Forever <=< decode. This fixed the issues I had.

Am I correct in my assumptions? Maybe the load API is problematic and should be removed?

I just wanted to share this so it might help others if they trip on these kind of bugs.

Thanks!