Skip to content
Browse files

A bug fix for freetype.Font.render_to()

The freetype.Font.render_to() method did not check that was not NULL, so would segfault. This patch adds the NULL check and corresponding unit test.
  • Loading branch information...
llindstrom committed Apr 4, 2017
1 parent 6668f62 commit 6d0e97a38b5d2d549f1fee8b912a072731ea33bb
Showing with 16 additions and 0 deletions.
  1. +4 −0 src/_freetype.c
  2. +12 −0 test/
@@ -2028,6 +2028,10 @@ _ftfont_render_to(PgFontObject *self, PyObject *args, PyObject *kwds)
goto error;

surface = PySurface_AsSurface(surface_obj);
if (!surface) {
PyErr_SetString(PyExc_SDLError, "display Surface quit");
goto error;
if (_PGFT_Render_ExistingSurface(self->freetype, self,
&render, text, surface,
xpos, ypos, &fg_color,
@@ -1398,6 +1398,18 @@ def ref_items(seq):
self.assertEqual(getrefcount(o[i]), 2,
"refcount fail for item %d" % i)

def test_display_surface_quit(self):
"""Font.render_to() on a closed display surface"""

# The Font.render_to() method checks that is NULL
# and raise a exception if it is. This fixes a bug in Pygame revision
# 0600ea4f1cfb and earlier where Pygame segfaults instead.
null_surface = pygame.Surface.__new__(pygame.Surface)
f = self._TEST_FONTS['sans']
self.assertRaises(pygame.error, f.render_to,
null_surface, (0, 0), "Crash!", size=12)

class FreeTypeTest(unittest.TestCase):

def test_resolution(self):

0 comments on commit 6d0e97a

Please sign in to comment.
You can’t perform that action at this time.