Skip to content

Commit

Permalink
Another attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
novialriptide committed Oct 30, 2023
1 parent 79e6d25 commit 3ed49bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
29 changes: 0 additions & 29 deletions src_c/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ static SDL_Surface *
pg_DisplayFormat(SDL_Surface *surface);
static int
_PgSurface_SrcAlpha(SDL_Surface *surf);
static int
_is_pg_window_active();

#if !SDL_VERSION_ATLEAST(2, 0, 10)
static Uint32
Expand Down Expand Up @@ -1769,9 +1767,6 @@ surf_get_clip(PyObject *self, PyObject *_null)
static PyObject *
surf_fill(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
{
if (!_is_pg_window_active())
return RAISE(PyExc_RuntimeError, "pygame display window is not active");

SDL_Surface *surf = pgSurface_AsSurface(self);
SDL_Rect *rect, temp;
PyObject *r = NULL;
Expand Down Expand Up @@ -1860,9 +1855,6 @@ surf_fill(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
static PyObject *
surf_blit(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
{
if (!_is_pg_window_active())
return RAISE(PyExc_RuntimeError, "pygame display window is not active");

SDL_Surface *src, *dest = pgSurface_AsSurface(self);
SDL_Rect *src_rect, temp;
PyObject *argpos, *argrect = NULL;
Expand Down Expand Up @@ -1935,9 +1927,6 @@ surf_blit(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
static PyObject *
surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
{
if (!_is_pg_window_active())
return RAISE(PyExc_RuntimeError, "pygame display window is not active");

SDL_Surface *src, *dest = pgSurface_AsSurface(self);
SDL_Rect *src_rect, temp;
PyObject *srcobject = NULL, *argpos = NULL, *argrect = NULL;
Expand Down Expand Up @@ -2180,9 +2169,6 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
static PyObject *
surf_fblits(pgSurfaceObject *self, PyObject *const *args, Py_ssize_t nargs)
{
if (!_is_pg_window_active())
return RAISE(PyExc_RuntimeError, "pygame display window is not active");

SDL_Surface *src, *dest = pgSurface_AsSurface(self);
SURF_INIT_CHECK(dest)

Expand Down Expand Up @@ -2458,21 +2444,6 @@ _PgSurface_SrcAlpha(SDL_Surface *surf)
return (mode != SDL_BLENDMODE_NONE);
}

/*
* Returns 1 if active, 0 if not.
* See: https://github.com/pygame-community/pygame-ce/issues/2523
*/
static int
_is_pg_window_active()
{
SDL_Surface *win_surface;
if (!SDL_GetWindowSurface(&win_surface)) {
return 0;
}

return 1;
}

static PyObject *
surf_get_flags(PyObject *self, PyObject *_null)
{
Expand Down
6 changes: 6 additions & 0 deletions src_c/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ static PyObject *
window_destroy(pgWindowObject *self, PyObject *_null)
{
if (self->_win) {
if (self->_is_borrowed && pg_GetDefaultWindow() == self->_win) {
pgSurface_AsSurface(pg_GetDefaultWindowSurface()) = NULL;
pg_SetDefaultWindowSurface(NULL);
pg_SetDefaultWindow(NULL);
}

SDL_DestroyWindow(self->_win);
self->_win = NULL;
}
Expand Down

0 comments on commit 3ed49bd

Please sign in to comment.