17cupsofcoffee / tetra

🎮 A simple 2D game framework written in Rust

Home Page:https://tetra.seventeencups.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SoundInstace.stop() doesn't work

Im-Oab opened this issue · comments

commented

Summary:
After get SoundInstance from Sound.play_with(), I try to stop the sound using SoundInstance.stop() but sound doesn't stop.

Steps to reproduce:

  • Create Sound object and call Sound.play_with(). Keep returned "SoundInstance" for using it later.
  • Wait for few seconds and call SoundInstance.stop()
  • Sound doesn't stop.

Expected behavior:
Sound should stop after call SoundInstace.stop()

Additional info:
OSX, tetra 0.5.6, play .wav file

I'm not able to replicate this 😢

I modified the audio example from Tetra to use play_with for channel1, and the stop button still worked. I also tried switching out powerup.wav for the longer bgm.wav so that I could try waiting a few seconds to stop it, but this didn't make any difference.

Are you able to provide an example of some code that triggers the issue? Wondering if it might be some edge case I've not thought of.

Ah, actually - are you dropping the SoundInstance after you stop it?

As soon as the SoundInstance gets dropped, the underlying Rodio Source stops reading from it - if the Source hasn't updated and seen the stop command at that point, then it might get ignored. This is very unintuitive and I need to change it...

commented

I think this is my fault. I dropped SoundInstance object after called stop(). If I keep the object for few update(). Sound will stop.

It's not your fault, that behaviour isn't really what I intended when I implemented it! I have some ideas on how to fix it - will let you know when there's an update.

I have pushed a fix to the main branch - does the issue still occur if you switch your dependency to:

tetra = { git = "https://github.com/17cupsofcoffee/tetra", branch = "main" }

If so, I'll release a patch tonight or tomorrow with the fix included.

commented

Thank Joe, it fixed the issue.