Skip to content

arcade.Sound.stop() doesn't work #839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VV0JC13CH opened this issue Apr 2, 2021 · 6 comments
Closed

arcade.Sound.stop() doesn't work #839

VV0JC13CH opened this issue Apr 2, 2021 · 6 comments

Comments

@VV0JC13CH
Copy link

Bug Report

Actual behavior:

Exception:
File "venv/lib/python3.9/site-packages/arcade/sound.py", line 72, in stop
media.Source._players.remove(player)
ValueError: list.remove(x): x not in list

Expected behavior:

Sound is going to stop playing

Steps to reproduce/example code:

Launch: https://arcade.academy/examples/background_music.html#background-music and wait until end of first song :-)

Enhancement request:

What should be added/changed?

What would it help with?

Documentation request:

What documentation needs to change?

Where is it located?

arcade/sound.py

What is wrong with it? How can it be improved?

ValueError: list.remove(x): x not in list

Trackback from background-music example:
Traceback (most recent call last):
File "test.py", line 105, in
main()
File "test.py", line 101, in main
arcade.run()
File "venv/lib/python3.9/site-packages/arcade/window_commands.py", line 240, in run
pyglet.app.run()
File "venv/lib/python3.9/site-packages/pyglet/app/init.py", line 107, in run
event_loop.run()
File "venv/lib/python3.9/site-packages/pyglet/app/base.py", line 167, in run
timeout = self.idle()
File "venv/lib/python3.9/site-packages/pyglet/app/base.py", line 237, in idle
redraw_all = self.clock.call_scheduled_functions(dt)
File "venv/lib/python3.9/site-packages/pyglet/clock.py", line 292, in call_scheduled_functions
item.func(now - item.last_ts, *item.args, **item.kwargs)
File "venv/lib/python3.9/site-packages/arcade/application.py", line 223, in _dispatch_updates
self.dispatch_event('on_update', delta_time)
File "venv/lib/python3.9/site-packages/pyglet/window/init.py", line 1333, in dispatch_event
if EventDispatcher.dispatch_event(self, *args) != False:
File "venv/lib/python3.9/site-packages/pyglet/event.py", line 415, in dispatch_event
if getattr(self, event_type)(*args):
File "test.py", line 94, in on_update
self.music.stop(self.current_player)
File "venv/lib/python3.9/site-packages/arcade/sound.py", line 72, in stop
media.Source._players.remove(player)
ValueError: list.remove(x): x not in list

@einarf
Copy link
Member

einarf commented Apr 30, 2021

I'm guessing the sound was already removed by the on_player_eos callback. It could be a good idea to always ask if the player is in the player list before removing it? Might be a couple race conditions here?

@Cleptomania have any thoughts on this?

arcade/arcade/sound.py

Lines 57 to 72 in a042093

def _on_player_eos():
media.Source._players.remove(player)
# There is a closure on player. To get the refcount to 0,
# we need to delete this function.
player.on_player_eos = None
player.on_player_eos = _on_player_eos
return player
def stop(self, player: media.Player) -> None:
"""
Stop a currently playing sound.
"""
player.pause()
player.delete()
media.Source._players.remove(player)

@Cleptomania
Copy link
Member

That probably is what’s happening. I think just checking if it’s in the list would be enough to prevent it from happening. We shouldn’t need to perform the check within on_player_eos as it could never be triggered after a stop has been. So if I just add a check in the stop functions I think we’d be good. I’ll do some testing with it tomorrow and push it to the development branch if that if that seems to work.

@einarf
Copy link
Member

einarf commented Apr 30, 2021

It might as well go in maintenance so we can push that out with a couple of other fixes

@Cleptomania
Copy link
Member

I've pushed a fix for this to maintenance.

@Cleptomania
Copy link
Member

Also found that this example hasn't been updated to work with the new sound changes either and had some other unrelated issues. I'm going to update that as well.

@einarf
Copy link
Member

einarf commented May 25, 2021

2.5.7 is released

@einarf einarf closed this as completed May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants