Skip to content

Commit 725074c

Browse files
committed
Improved Window.flip error message when no surface is associated with it
1 parent 73c9df0 commit 725074c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src_c/window.c

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

186+
VIDEO_INIT_CHECK();
187+
186188
Py_BEGIN_ALLOW_THREADS;
187189
result = SDL_UpdateWindowSurface(self->_win);
188190
Py_END_ALLOW_THREADS;
189-
if (result)
191+
if (result) {
192+
if (!self->surf) {
193+
return RAISE(pgExc_SDLError,
194+
"the Window has no surface associated with it, did "
195+
"you forget to call Window.get_surface()");
196+
}
190197
return RAISE(pgExc_SDLError, SDL_GetError());
198+
}
191199
Py_RETURN_NONE;
192200
}
193201

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)