@@ -324,8 +324,9 @@ mouse_get_visible(PyObject *self, PyObject *_null)
324324
325325#if SDL_VERSION_ATLEAST (3 , 0 , 0 )
326326 SDL_Window * win = pg_GetDefaultWindow ();
327- result =
328- win ? (PG_CursorVisible () && !SDL_GetWindowRelativeMouseMode (win )) : 0 ;
327+
328+ /* If win is NULL, SDL_GetWindowRelativeMouseMode returns false */
329+ result = (PG_CursorVisible () && !SDL_GetWindowRelativeMouseMode (win ));
329330#else
330331 result = (PG_CursorVisible () && !SDL_GetRelativeMouseMode ());
331332#endif
@@ -618,8 +619,8 @@ mouse_set_relative_mode(PyObject *self, PyObject *arg)
618619 if (mode == -1 ) {
619620 return NULL ;
620621 }
621- #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
622622 SDL_Window * win = pg_GetDefaultWindow ();
623+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
623624 if (!win ) {
624625 return RAISE (pgExc_SDLError ,
625626 "display.set_mode has not been called yet." );
@@ -628,6 +629,15 @@ mouse_set_relative_mode(PyObject *self, PyObject *arg)
628629 return RAISE (pgExc_SDLError , SDL_GetError ());
629630 }
630631#else
632+ if (!win ) {
633+ if (PyErr_WarnEx (PyExc_DeprecationWarning ,
634+ "Calling mouse.set_relative_mode before calling "
635+ "display.set_mode has been deprecated and may raise "
636+ "errors in the future." ,
637+ 1 ) == -1 ) {
638+ return NULL ;
639+ }
640+ }
631641 if (SDL_SetRelativeMouseMode ((SDL_bool )mode )) {
632642 return RAISE (pgExc_SDLError , SDL_GetError ());
633643 }
0 commit comments