Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src_c/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ aaline(PyObject *self, PyObject *arg, PyObject *kwargs)
return NULL; /* Exception already set. */
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (!blend) {
if (PyErr_WarnEx(
PyExc_DeprecationWarning,
Expand All @@ -128,8 +131,6 @@ aaline(PyObject *self, PyObject *arg, PyObject *kwargs)
}
}

surf = pgSurface_AsSurface(surfobj);

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
"unsupported surface bit depth (%d) for drawing",
Expand Down Expand Up @@ -191,6 +192,7 @@ line(PyObject *self, PyObject *arg, PyObject *kwargs)
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
Expand Down Expand Up @@ -265,6 +267,7 @@ aalines(PyObject *self, PyObject *arg, PyObject *kwargs)
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
Expand Down Expand Up @@ -398,6 +401,7 @@ lines(PyObject *self, PyObject *arg, PyObject *kwargs)
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
Expand Down Expand Up @@ -520,6 +524,7 @@ arc(PyObject *self, PyObject *arg, PyObject *kwargs)
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
Expand Down Expand Up @@ -595,6 +600,7 @@ ellipse(PyObject *self, PyObject *arg, PyObject *kwargs)
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
Expand Down Expand Up @@ -678,6 +684,7 @@ circle(PyObject *self, PyObject *args, PyObject *kwargs)
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
Expand Down Expand Up @@ -767,6 +774,7 @@ polygon(PyObject *self, PyObject *arg, PyObject *kwargs)
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
Expand Down Expand Up @@ -884,6 +892,8 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs)
}

surf = pgSurface_AsSurface(surfobj);
SURF_INIT_CHECK(surf)

if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
return PyErr_Format(PyExc_ValueError,
"unsupported surface bit depth (%d) for drawing",
Expand Down
7 changes: 7 additions & 0 deletions src_c/include/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,13 @@ PYGAMEAPI_EXTERN_SLOTS(math);
* functions in Python 3.
*/

#define SURF_INIT_CHECK(SDL_SurfObj) \
{ \
if (!SDL_SurfObj) { \
return RAISE(pgExc_SDLError, "Surface is not initialized"); \
} \
}

static PG_INLINE PyObject *
pg_tuple_couple_from_values_int(int val1, int val2)
{
Expand Down
Loading