Skip to content

Commit aead275

Browse files
authored
Merge pull request #2860 from pygame-community/ankith26-window-autoinit
Run display autoinit on window API, fixes
2 parents 7f5c4d9 + ed157de commit aead275

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src_c/display.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pg_display_quit(PyObject *self, PyObject *_null)
196196

197197
pg_mod_autoquit(IMPPREFIX "event");
198198
pg_mod_autoquit(IMPPREFIX "time");
199-
pg_mod_autoquit(IMPPREFIX "_window");
199+
pg_mod_autoquit(IMPPREFIX "window");
200200

201201
if (SDL_WasInit(SDL_INIT_VIDEO)) {
202202
SDL_QuitSubSystem(SDL_INIT_VIDEO);

src_c/window.c

+22-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "doc/sdl2_video_doc.h"
88
#include "doc/window_doc.h"
99

10+
static int is_window_mod_init = 0;
11+
1012
#if !defined(__APPLE__)
1113
static char *icon_defaultname = "pygame_icon.bmp";
1214
static int icon_colorkey = 0;
@@ -759,6 +761,11 @@ window_init(pgWindowObject *self, PyObject *args, PyObject *kwargs)
759761
const char *_key_str;
760762
int _value_bool;
761763

764+
// ensure display is init at this point, diplay init automatically calls
765+
// the window init in this module
766+
if (!pg_mod_autoinit(IMPPREFIX "display"))
767+
return -1;
768+
762769
_kw = PyDict_New();
763770
if (!_kw)
764771
return -1;
@@ -954,6 +961,11 @@ window_from_display_module(PyTypeObject *cls, PyObject *_null)
954961
return NULL;
955962
}
956963

964+
// ensure display is init at this point, diplay init automatically calls
965+
// the window init in this module
966+
if (!pg_mod_autoinit(IMPPREFIX "display"))
967+
return NULL;
968+
957969
SDL_Window *window = pg_GetDefaultWindow();
958970
if (!window) {
959971
return RAISE(pgExc_SDLError,
@@ -999,14 +1011,20 @@ window_repr(pgWindowObject *self)
9991011
static PyObject *
10001012
_window_internal_mod_init(PyObject *self, PyObject *_null)
10011013
{
1002-
SDL_AddEventWatch(_resize_event_watch, NULL);
1014+
if (!is_window_mod_init) {
1015+
SDL_AddEventWatch(_resize_event_watch, NULL);
1016+
is_window_mod_init = 1;
1017+
}
10031018
Py_RETURN_NONE;
10041019
}
10051020

10061021
static PyObject *
10071022
_window_internal_mod_quit(PyObject *self, PyObject *_null)
10081023
{
1009-
SDL_DelEventWatch(_resize_event_watch, NULL);
1024+
if (is_window_mod_init) {
1025+
SDL_DelEventWatch(_resize_event_watch, NULL);
1026+
is_window_mod_init = 0;
1027+
}
10101028
Py_RETURN_NONE;
10111029
}
10121030

@@ -1083,9 +1101,9 @@ static PyMethodDef _window_methods[] = {
10831101
{"get_grabbed_window", (PyCFunction)get_grabbed_window, METH_NOARGS,
10841102
DOC_SDL2_VIDEO_GETGRABBEDWINDOW},
10851103
{"_internal_mod_init", (PyCFunction)_window_internal_mod_init, METH_NOARGS,
1086-
"auto initialize for _window module"},
1104+
"auto initialize for window module"},
10871105
{"_internal_mod_quit", (PyCFunction)_window_internal_mod_quit, METH_NOARGS,
1088-
"auto quit for _window module"},
1106+
"auto quit for window module"},
10891107
{NULL, NULL, 0, NULL}};
10901108

10911109
MODINIT_DEFINE(window)

0 commit comments

Comments
 (0)