Skip to content

Commit

Permalink
Merge pull request #2633 from Matiiss/matiiss-improve-window-flip-err…
Browse files Browse the repository at this point in the history
…-msg

Improved `Window.flip` error message when no surface is associated with the `Window`
  • Loading branch information
Starbuck5 committed Feb 18, 2024
1 parent c5bacc0 commit a673cbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src_c/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions test/window_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit a673cbe

Please sign in to comment.