haskell-game/sdl2-mixer

Randomly refuses to play

HiiGHoVuTi opened this issue · 3 comments

Hi ! It's been a few days and I've struggled with this bug as it seemed totally random. Basically I'm using the library to play a whole song, and short samples. Here is the code:

fileOn :: String -> Mix.Channel -> IO ThreadId
fileOn fpath channel = forkIO $ do
  music <- Mix.load fpath
  _ <- Mix.playOn channel Mix.Once music
  delayWhile $ Mix.playing channel
  Mix.free music

I've never had the short sample (<1s wav file) not play, but the long song (.mp3) refuses to show up randomly. It happens about 1/5 times on my fast computer, and 4/5 times on my friend's slower computer. Maybe this has nothing to do with speed, but I'll leave this there.
Maybe I'm calling this wrong, it's basically only used as a side effect in do blocks, and I do nothing with the thread id.

Sorry if it's all over the place, I can't figure out if the problem comes from me or the library.
Thanks in advance.

Issue was unrelated to the library.

dpwiz commented

@HiiGHoVuTi what was it?

It was an absurd error. Well first of all, my library setup was shaky, so I had to move the init calls around, stop the tracks when I'm done etc.
But the bug was that when comparing two Double values, >= and > wouldn't give the same result, and that lead to my music bug after a huge butterfly effect. So my game was running at some framerate that somehow allowed a Double number to be exactly equal to 0.