@@ -324,8 +324,9 @@ mouse_get_visible(PyObject *self, PyObject *_null)
324
324
325
325
#if SDL_VERSION_ATLEAST (3 , 0 , 0 )
326
326
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 ));
329
330
#else
330
331
result = (PG_CursorVisible () && !SDL_GetRelativeMouseMode ());
331
332
#endif
@@ -618,8 +619,8 @@ mouse_set_relative_mode(PyObject *self, PyObject *arg)
618
619
if (mode == -1 ) {
619
620
return NULL ;
620
621
}
621
- #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
622
622
SDL_Window * win = pg_GetDefaultWindow ();
623
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
623
624
if (!win ) {
624
625
return RAISE (pgExc_SDLError ,
625
626
"display.set_mode has not been called yet." );
@@ -628,6 +629,15 @@ mouse_set_relative_mode(PyObject *self, PyObject *arg)
628
629
return RAISE (pgExc_SDLError , SDL_GetError ());
629
630
}
630
631
#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
+ }
631
641
if (SDL_SetRelativeMouseMode ((SDL_bool )mode )) {
632
642
return RAISE (pgExc_SDLError , SDL_GetError ());
633
643
}
0 commit comments