diff --git a/src_c/window.c b/src_c/window.c index fddbc6f374..0c4ce65cb1 100644 --- a/src_c/window.c +++ b/src_c/window.c @@ -183,11 +183,18 @@ window_flip(pgWindowObject *self) { int result; + if (!self->surf) { + return RAISE(pgExc_SDLError, + "the Window has no surface associated with it, did " + "you forget to call Window.get_surface()"); + } + Py_BEGIN_ALLOW_THREADS; result = SDL_UpdateWindowSurface(self->_win); Py_END_ALLOW_THREADS; - if (result) + if (result) { return RAISE(pgExc_SDLError, SDL_GetError()); + } Py_RETURN_NONE; } diff --git a/test/window_test.py b/test/window_test.py index 4b6b9fdd3a..302ccc78a4 100644 --- a/test/window_test.py +++ b/test/window_test.py @@ -360,6 +360,15 @@ def test_window_flip(self): self.assertIs(win.flip(), None) win.destroy() + # creates a new window with no surface associated + win = Window(size=(640, 480)) + self.assertRaisesRegex( + pygame.error, + "the Window has no surface associated with it, did you forget to call Window.get_surface()", + win.flip, + ) + win.destroy() + def tearDown(self): self.win.destroy()