Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src_c/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,6 @@ pg_init(PyObject *self, PyObject *_null)
/* IMPPREFIX "_sdl2.controller", Is this required? Comment for now*/
NULL};

#if SDL_VERSION_ATLEAST(3, 0, 0)
// In SDL3, specify that signal handlers should not be enabled.
// By default, unlike SDL2, these signal handlers convert into QUIT
// events. However, if QUIT events / events aren't being handled,
// this leaves people unable to quit their script. Plus it's different
// than SDL2 behavior.
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
#endif

/*nice to initialize timer, so startup time will reflec pg_init() time*/
#if defined(WITH_THREAD) && !defined(MS_WIN32) && defined(SDL_INIT_EVENTTHREAD)
pg_sdl_was_init = PG_InitSubSystem(SDL_INIT_EVENTTHREAD | PG_INIT_TIMER |
Expand Down Expand Up @@ -2130,6 +2121,15 @@ MODINIT_DEFINE(base)

PyObject *module, *apiobj;

#if SDL_VERSION_ATLEAST(3, 0, 0)
// In SDL3, specify that signal handlers should not be enabled.
// By default, unlike SDL2, these signal handlers convert into QUIT
// events. However, if QUIT events / events aren't being handled,
// this leaves people unable to quit their script. Plus it's different
// than SDL2 behavior.
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
#endif
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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()

Copy link
Member

@ankith26 ankith26 Dec 13, 2025

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)

Copy link
Member Author

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.


/* import need modules. Do this first so if there is an error
the module is not loaded.
*/
Expand Down
Loading