-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Prevent segfault due to division by zero in music.get_pos #2426
Prevent segfault due to division by zero in music.get_pos #2426
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about returning -1 instead of raising
I also think returning a |
Updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works fine for me
By returning -1, does it raise an error now ? Because I still have the same result as before (nothing printed). |
It doesn't raise an error. The code in the original comment prints nothing now because that is what is expected. Modifying the reproducer a bit to import pygame
pygame.init()
pygame.mixer.init()
print(pygame.mixer.music.get_pos()) Should print a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code and doc changes LGTM, thanks for the PR 🎉
I also just remembered, a simple unittest addition would be nice, but 'm approving this PR nonetheless
The program still crashes in my side. I'm on Windows 11, perhaps I setup wrongly pygame-ce (I'm using oddbookworm's version). |
You should be able to grab a wheel from the CI runs and install the wheel to check it |
I agree, but as said in my first message, I couldn’t get it to work. If you have a suggestion to resolve the issue I was seeing with unit testing, I’ll happily write a test |
music.get_pos now returns -1 on failure
@pmp-p reported an issue in discord where this code can crash due to a division by zero:
I tried to write a regression test for this fix, but I couldn't reliably reproduce it in a test environment. Because the variables involved are static to the
music.c
file, I believe this is only possible before any music has ever been loaded, and because other tests run before the created test, those static variables retain their last value, even ifpygame.mixer.quit()
orpygame.quit()
has been called and mixer has been reinitialized@bilhox reported that they didn't get the floating point exception on windows 11 (pmp-p and I are both using linux), but I suspect that is windows doing windows things and not actually showing the parachute info.
For reference, here is the parachute dump I get:
And the gdb result on receipt of the exception