-
-
Notifications
You must be signed in to change notification settings - Fork 217
Move SDL hint so it always triggers on import #3659
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
base: main
Are you sure you want to change the base?
Conversation
Rather than relying on pygame.init() being called, since not all workflows would do that.
📝 WalkthroughWalkthroughThe change relocates SDL3 signal handler hint configuration from pg_init to base module initialization, preserving functionality while altering the initialization sequence. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5–10 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (3)📓 Common learnings📚 Learning: 2025-09-01T20:18:57.500ZApplied to files:
📚 Learning: 2025-08-30T21:11:00.240ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| // this leaves people unable to quit their script. Plus it's different | ||
| // than SDL2 behavior. | ||
| SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); | ||
| #endif |
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.
Now that this logic has been moved here, have you tested that something like say, quit+init doesn't reset this hint? I feel like something like this must be done at one of the init functions, say display.init or the internal event init function.
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.
Dang I didn't test that because I expected hints to be global. But no, I guess quitting SDL resets them.
It needs to get called on every possible event path that could initialize event? mixer.init, display.init, others?
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.
Test program
import pygame
pygame.display.init()
clock = pygame.time.Clock()
running = True
try:
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("RECEIVED QUIT EVENT OMG 1")
running = False
clock.tick(60)
except KeyboardInterrupt:
print("KEYBOARD INTERRUPTED 1")
pygame.display.quit()
pygame.init()
print("initialized 1")
clock = pygame.time.Clock()
running = True
try:
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("RECEIVED QUIT EVENT OMG 1")
running = False
clock.tick(60)
except KeyboardInterrupt:
print("KEYBOARD INTERRUPTED 1")
pygame.quit()
pygame.init()
print("initialized 2")
try:
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("RECEIVED QUIT EVENT OMG 2")
running = False
clock.tick(60)
except KeyboardInterrupt:
print("KEYBOARD INTERRUPTED 2")
pygame.quit()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.
I think the hint should be set in pgEvent_AutoInit, any other init function that needs event to be init must call pg_mod_autoinit(IMPPREFIX "event") (like display.init already does it)
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.
Some other SDL things initialize event internally, so it can be potentially non obvious. Like I ran into this problem with SDL_INIT_AUDIO.
Rather than relying on pygame.init() being called, since not all workflows would do that.
This just moves where the code added in #3654 triggers. Thanks to reviewers on that for reviewing it so quickly, I'm sort of embarrassed to already want to change it.
But I was thinking about what Ankith said in his review, that we wouldn't want SDL to ever override signal handlers from Python. And my previous PR didn't do that. It just turned it off if one happened to call pygame.init(). Like in my audio example script in my other recent PR I don't call pygame.init(), I just call audio.init().