pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
773 stars 120 forks source link

pygame.mixer.music endevent triggered by set_volume #2797

Closed scribblecrumb closed 1 month ago

scribblecrumb commented 2 months ago

Environment:

Current behavior:

I set up a custom event to be triggered when the music ends via set_endevent.

MUSIC_END = pygame.USEREVENT + 1
pygame.mixer.music.set_endevent(MUSIC_END)

I found that the MUSIC_END event was being triggered both when the music ends and when pygame.mixer.music.set_volume is used.

Expected behavior:

I would expect for the endevent to only trigger when the music ends.

Screenshots

N/A

Steps to reproduce:

  1. Create a custom event using pygame.USEREVENT
  2. Set that event to queue when the music ends via pygame.mixer.music.set_endevent()
  3. Change the volume of the music using pygame.mixer.music.set_volume()

Test code N/A (i'll add one if i find time later to write one up)

Stack trace/error output/other error logs N/A

ankith26 commented 2 months ago

Hello!

I cannot reproduce this issue. I'm on Ubuntu 23.10 and using pygame-ce 2.4.1 (SDL 2.28.5, Python 3.11.6).

I tested with the music_drop_fade example that comes along with the pygame-ce install.

Please provide a minimal reproducer that triggers the bug for you, more factors other than calling set_volume may be involved in order to trigger this bug.

ankith26 commented 1 month ago
import random
import pygame

MYEVENT = pygame.USEREVENT + 1

class App:
    def __init__(self) -> None:
        pygame.init()
        self.display = pygame.display.set_mode([320, 180])
        path = "sample.mp3"
        pygame.mixer.music.load(path)
        pygame.mixer.music.play()
        pygame.mixer.music.set_endevent(MYEVENT)

    def check_events(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
            if event.type == pygame.KEYDOWN:
                pygame.mixer.music.set_volume(random.randint(0, 100) / 100)
            if event.type == MYEVENT:
                print("myevent")

    def update(self): ...

    def render(self):
        self.display.fill("white")
        pygame.display.flip()

    def run(self):
        while True:
            self.check_events()
            self.update()
            self.render()

if __name__ == "__main__":
    a = App()
    a.run()

Here is another sample I tested with (thanks to @pycoinfu for providing this) and I still cannot reproduce the issue. I am closing this issue for now, but feel free to re-open if you can write a similar script that reproduces the issue for you.