|
7 | 7 | #include "doc/sdl2_video_doc.h" |
8 | 8 | #include "doc/window_doc.h" |
9 | 9 |
|
| 10 | +static int is_window_mod_init = 0; |
| 11 | + |
10 | 12 | #if !defined(__APPLE__) |
11 | 13 | static char *icon_defaultname = "pygame_icon.bmp"; |
12 | 14 | static int icon_colorkey = 0; |
@@ -759,6 +761,11 @@ window_init(pgWindowObject *self, PyObject *args, PyObject *kwargs) |
759 | 761 | const char *_key_str; |
760 | 762 | int _value_bool; |
761 | 763 |
|
| 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 | + |
762 | 769 | _kw = PyDict_New(); |
763 | 770 | if (!_kw) |
764 | 771 | return -1; |
@@ -954,6 +961,11 @@ window_from_display_module(PyTypeObject *cls, PyObject *_null) |
954 | 961 | return NULL; |
955 | 962 | } |
956 | 963 |
|
| 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 | + |
957 | 969 | SDL_Window *window = pg_GetDefaultWindow(); |
958 | 970 | if (!window) { |
959 | 971 | return RAISE(pgExc_SDLError, |
@@ -999,14 +1011,20 @@ window_repr(pgWindowObject *self) |
999 | 1011 | static PyObject * |
1000 | 1012 | _window_internal_mod_init(PyObject *self, PyObject *_null) |
1001 | 1013 | { |
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 | + } |
1003 | 1018 | Py_RETURN_NONE; |
1004 | 1019 | } |
1005 | 1020 |
|
1006 | 1021 | static PyObject * |
1007 | 1022 | _window_internal_mod_quit(PyObject *self, PyObject *_null) |
1008 | 1023 | { |
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 | + } |
1010 | 1028 | Py_RETURN_NONE; |
1011 | 1029 | } |
1012 | 1030 |
|
@@ -1083,9 +1101,9 @@ static PyMethodDef _window_methods[] = { |
1083 | 1101 | {"get_grabbed_window", (PyCFunction)get_grabbed_window, METH_NOARGS, |
1084 | 1102 | DOC_SDL2_VIDEO_GETGRABBEDWINDOW}, |
1085 | 1103 | {"_internal_mod_init", (PyCFunction)_window_internal_mod_init, METH_NOARGS, |
1086 | | - "auto initialize for _window module"}, |
| 1104 | + "auto initialize for window module"}, |
1087 | 1105 | {"_internal_mod_quit", (PyCFunction)_window_internal_mod_quit, METH_NOARGS, |
1088 | | - "auto quit for _window module"}, |
| 1106 | + "auto quit for window module"}, |
1089 | 1107 | {NULL, NULL, 0, NULL}}; |
1090 | 1108 |
|
1091 | 1109 | MODINIT_DEFINE(window) |
|
0 commit comments