Skip to content

Commit 627c9de

Browse files
authored
Merge pull request #3509 from MightyJosip/sdl3-init
Fix init functions with SDL3 build
2 parents a82eaef + 5b6ecba commit 627c9de

File tree

7 files changed

+21
-14
lines changed

7 files changed

+21
-14
lines changed

src_c/_pygame.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
151151
#define PG_EventEnabled(type) SDL_EventEnabled(type)
152152
#define PG_SetJoystickEventsEnabled(enabled) \
153153
SDL_SetJoystickEventsEnabled(enabled)
154+
#define PG_InitSubSystem(flags) SDL_InitSubSystem(flags)
154155

155156
#define PG_FIND_VNUM_MAJOR(ver) SDL_VERSIONNUM_MAJOR(ver)
156157
#define PG_FIND_VNUM_MINOR(ver) SDL_VERSIONNUM_MINOR(ver)
@@ -316,6 +317,12 @@ PG_MapRGB(PG_PixelFormat *format, const SDL_Palette *palette, Uint8 r, Uint8 g,
316317
return SDL_MapRGB(format, r, g, b);
317318
}
318319

320+
static inline bool
321+
PG_InitSubSystem(Uint32 flags)
322+
{
323+
return SDL_InitSubSystem(flags) == 0;
324+
}
325+
319326
/* Mask to test if surface flags are in a fullscreen window.
320327
* SDL_WINDOW_FULLSCREEN_DESKTOP works here because it also contains
321328
* SDL_WINDOW_FULLSCREEN. */

src_c/_sdl2/controller.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static PyObject *
2626
controller_module_init(PyObject *module, PyObject *_null)
2727
{
2828
if (!SDL_WasInit(SDL_INIT_GAMECONTROLLER)) {
29-
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)) {
29+
if (!PG_InitSubSystem(SDL_INIT_GAMECONTROLLER)) {
3030
return RAISE(pgExc_SDLError, SDL_GetError());
3131
}
3232
}

src_c/base.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static PyObject *pgExc_BufferError = NULL;
7878
/* Only one instance of the state per process. */
7979
static PyObject *pg_quit_functions = NULL;
8080
static int pg_is_init = 0;
81-
static int pg_sdl_was_init = 0;
81+
static bool pg_sdl_was_init = 0;
8282
SDL_Window *pg_default_window = NULL;
8383
pgSurfaceObject *pg_default_screen = NULL;
8484
static int pg_env_blend_alpha_SDL2 = 0;
@@ -348,10 +348,10 @@ pg_init(PyObject *self, PyObject *_null)
348348

349349
/*nice to initialize timer, so startup time will reflec pg_init() time*/
350350
#if defined(WITH_THREAD) && !defined(MS_WIN32) && defined(SDL_INIT_EVENTTHREAD)
351-
pg_sdl_was_init = SDL_Init(SDL_INIT_EVENTTHREAD | PG_INIT_TIMER |
352-
PG_INIT_NOPARACHUTE) == 0;
351+
pg_sdl_was_init = PG_InitSubSystem(SDL_INIT_EVENTTHREAD | PG_INIT_TIMER |
352+
PG_INIT_NOPARACHUTE);
353353
#else
354-
pg_sdl_was_init = SDL_Init(PG_INIT_TIMER | PG_INIT_NOPARACHUTE) == 0;
354+
pg_sdl_was_init = PG_InitSubSystem(PG_INIT_TIMER | PG_INIT_NOPARACHUTE);
355355
#endif
356356

357357
pg_env_blend_alpha_SDL2 = SDL_getenv("PYGAME_BLEND_ALPHA_SDL2") != NULL;
@@ -382,7 +382,7 @@ pg_atexit_quit(void)
382382
successful SDL_Init.
383383
*/
384384
if (pg_sdl_was_init) {
385-
pg_sdl_was_init = 0;
385+
pg_sdl_was_init = false;
386386
SDL_Quit();
387387
}
388388
}

src_c/display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pg_display_init(PyObject *self, PyObject *_null)
242242
return NULL;
243243
}
244244

245-
if (SDL_InitSubSystem(SDL_INIT_VIDEO)) {
245+
if (!PG_InitSubSystem(SDL_INIT_VIDEO)) {
246246
return RAISE(pgExc_SDLError, SDL_GetError());
247247
}
248248
}

src_c/joystick.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static PyObject *
3939
init(PyObject *self, PyObject *_null)
4040
{
4141
if (!SDL_WasInit(SDL_INIT_JOYSTICK)) {
42-
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK)) {
42+
if (!PG_InitSubSystem(SDL_INIT_JOYSTICK)) {
4343
return RAISE(pgExc_SDLError, SDL_GetError());
4444
}
4545
PG_SetJoystickEventsEnabled(SDL_TRUE);

src_c/mixer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ _init(int freq, int size, int channels, int chunk, char *devicename,
444444
SDL_setenv("SDL_AUDIODRIVER", "directsound", 1);
445445
}
446446

447-
if (SDL_InitSubSystem(SDL_INIT_AUDIO)) {
447+
if (!PG_InitSubSystem(SDL_INIT_AUDIO)) {
448448
return RAISE(pgExc_SDLError, SDL_GetError());
449449
}
450450

src_c/time.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ accurate_delay(Sint64 ticks)
325325

326326
#if !SDL_VERSION_ATLEAST(3, 0, 0)
327327
if (!SDL_WasInit(SDL_INIT_TIMER)) {
328-
if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
328+
if (!PG_InitSubSystem(SDL_INIT_TIMER)) {
329329
PyErr_SetString(pgExc_SDLError, SDL_GetError());
330330
return -1;
331331
}
@@ -389,7 +389,7 @@ time_wait(PyObject *self, PyObject *arg)
389389

390390
#if !SDL_VERSION_ATLEAST(3, 0, 0)
391391
if (!SDL_WasInit(SDL_INIT_TIMER)) {
392-
if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
392+
if (!PG_InitSubSystem(SDL_INIT_TIMER)) {
393393
return RAISE(pgExc_SDLError, SDL_GetError());
394394
}
395395
}
@@ -479,7 +479,7 @@ time_set_timer(PyObject *self, PyObject *args, PyObject *kwargs)
479479
#if !SDL_VERSION_ATLEAST(3, 0, 0)
480480
/* just doublecheck that timer is initialized */
481481
if (!SDL_WasInit(SDL_INIT_TIMER)) {
482-
if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
482+
if (!PG_InitSubSystem(SDL_INIT_TIMER)) {
483483
ecode = PG_TIMER_SDL_ERROR;
484484
goto end;
485485
}
@@ -549,7 +549,7 @@ clock_tick_base(pgClockObject *self, PyObject *arg, int use_accurate_delay)
549549
#if !SDL_VERSION_ATLEAST(3, 0, 0)
550550
/*just doublecheck that timer is initialized*/
551551
if (!SDL_WasInit(SDL_INIT_TIMER)) {
552-
if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
552+
if (!PG_InitSubSystem(SDL_INIT_TIMER)) {
553553
return RAISE(pgExc_SDLError, SDL_GetError());
554554
}
555555
}
@@ -671,7 +671,7 @@ clock_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
671671

672672
#if !SDL_VERSION_ATLEAST(3, 0, 0)
673673
if (!SDL_WasInit(SDL_INIT_TIMER)) {
674-
if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
674+
if (!PG_InitSubSystem(SDL_INIT_TIMER)) {
675675
return RAISE(pgExc_SDLError, SDL_GetError());
676676
}
677677
}

0 commit comments

Comments
 (0)