microsoft / pxt-arcade

Arcade game editor based on Microsoft MakeCode
https://arcade.makecode.com
MIT License
477 stars 207 forks source link

music.stopAllSounds() doesn't stop all sounds #2541

Closed klausw closed 3 years ago

klausw commented 3 years ago

Describe the bug The music.stopAllSounds() method doesn't consistently stop sounds from playing.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://makecode.com/_YyAhiFUR8aaf
  2. Press A button to start the music loop
  3. Press A button again while music is playing
  4. Press B button to stop music

Expected behavior Music should stop playing, the B button event handler calls music.stopAllSounds()

Desktop (please complete the following information):

I've confirmed this behavior both in the Arcade simulator and on an Adafruit PyGamer. @mmoskal FYI since you've been working on the sound code.

klausw commented 3 years ago

This seems to be a race condition, stopping and immediately restarting a melody replaces the playingMelodies entry and the MelodyPlayer, but the first instance's playCore then unexpectedly calls unregisterMelody() while playing, leaving the melody in an unstoppable state.

PR https://github.com/microsoft/pxt-common-packages/pull/1196 fixes it for me, but I'm not sure if that's the correct way to handle it.