diff --git a/src_c/display.c b/src_c/display.c index 8f72dcbcc6..6418b58c75 100644 --- a/src_c/display.c +++ b/src_c/display.c @@ -707,6 +707,19 @@ _get_video_window_pos(int *x, int *y, int *center_window) return 0; } +static void +_check_window_resized(SDL_Window *window, int free_old_surf) +{ + SDL_Surface *sdl_surface = SDL_GetWindowSurface(window); + pgSurfaceObject *old_surface = pg_GetDefaultWindowSurface(); + if (sdl_surface != old_surface->surf) { + if (free_old_surf) { + SDL_FreeSurface(old_surface->surf); + } + old_surface->surf = sdl_surface; + } +} + static int SDLCALL pg_ResizeEventWatch(void *userdata, SDL_Event *event) { @@ -786,11 +799,7 @@ pg_ResizeEventWatch(void *userdata, SDL_Event *event) } if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - SDL_Surface *sdl_surface = SDL_GetWindowSurface(window); - pgSurfaceObject *old_surface = pg_GetDefaultWindowSurface(); - if (sdl_surface != old_surface->surf) { - old_surface->surf = sdl_surface; - } + _check_window_resized(window, 1); } return 0; } @@ -1374,6 +1383,7 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds) surface = pgSurface_New2(surf, newownedsurf != NULL); } else { + _check_window_resized(win, 0); pgSurface_SetSurface(surface, surf, newownedsurf != NULL); Py_INCREF(surface); }