Issue #58 resolved

FontManager.render("") ValueError: NULL pointer access

Chris Thompson
created an issue

I assume this isn't intended behavior; it certainly surprised me when I was hoping for an easy way to clear out text in the game I'm working on. SDL2 version 2.0.3, Python 3.3, and PySDL2 0.9.0; demonstrated from the console:

import sdl2
from sdl2.ext import FontManager
font = FontManager("C:\\Windows\\Fonts\\Arial.ttf")
font.render("Text")
# Returns an SDL_Surface object.
font.render("")
# Raises a "ValueError: NULL pointer access" exception.

Comments (3)

  1. Marcus von Appen repo owner

    I'm unable to recreate that issue on a Windows 7 machine with 32-bit and 64-bit builds. Can you make sure that you have installed the latest SDL2_ttf version as well as the latest version of PySDL2 (0.9.2) and give it another try?

  2. Chris Thompson reporter

    In my folder "C:\Program Files (x86)\eclipse\Workspace\Gamework\Gamework\bin" I have the latest 32-bit SDL2.dll (2.0.3.0) and SDL2_ttf.dll (2.0.12.0), among others. I deleted my old Python33\Lib\site-packages\sdl2 and PySDL2*.egg-info, then ran PySDL2-0.9.2's setup.py install. I assume that means I have a clean install of the newest stuff, but in a command prompt I still get:

    C:\Users\thomps4\Desktop\PySDL2-0.9.2>python
    Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> os.environ["PYSDL2_DLL_PATH"] = "C:\\Program Files (x86)\\eclipse\\Workspace\\Gamework\\Gamework\\bin"
    >>> import sdl2
    >>> from sdl2.ext import FontManager
    >>> font = FontManager("C:\\Windows\\Fonts\\Arial.ttf")
    >>> font.render("Text")
    <sdl2.surface.SDL_Surface object at 0x03304990>
    >>> font.render("")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File ".\sdl2\ext\font.py", line 344, in render
        return surface.contents
    ValueError: NULL pointer access
    
  3. Marcus von Appen repo owner

    I was able to reproduce that issue. For some fonts, the text size detection in SDL2_ttf might return a value > 0 for an empty string (most likely a broken font). Having said that, commit 660a7a5 should raise a proper error message, since SDL2_ttf does not support rendering empty text.

  4. Log in to comment