Skip to content

Commit 04cc697

Browse files
authored
Merge pull request #2633 from Matiiss/matiiss-improve-window-flip-err-msg
Improved `Window.flip` error message when no surface is associated with the `Window`
2 parents dddc7bf + f97d3c0 commit 04cc697

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src_c/window.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,18 @@ window_flip(pgWindowObject *self)
183183
{
184184
int result;
185185

186+
if (!self->surf) {
187+
return RAISE(pgExc_SDLError,
188+
"the Window has no surface associated with it, did "
189+
"you forget to call Window.get_surface()");
190+
}
191+
186192
Py_BEGIN_ALLOW_THREADS;
187193
result = SDL_UpdateWindowSurface(self->_win);
188194
Py_END_ALLOW_THREADS;
189-
if (result)
195+
if (result) {
190196
return RAISE(pgExc_SDLError, SDL_GetError());
197+
}
191198
Py_RETURN_NONE;
192199
}
193200

test/window_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ def test_window_flip(self):
360360
self.assertIs(win.flip(), None)
361361
win.destroy()
362362

363+
# creates a new window with no surface associated
364+
win = Window(size=(640, 480))
365+
self.assertRaisesRegex(
366+
pygame.error,
367+
"the Window has no surface associated with it, did you forget to call Window.get_surface()",
368+
win.flip,
369+
)
370+
win.destroy()
371+
363372
def tearDown(self):
364373
self.win.destroy()
365374

0 commit comments

Comments
 (0)