SDL_CreateTexture and SDL_CreateTextureFromSurface cause NULL pointer access down the line.

Issue #97 invalid
Former user created an issue

I'm writing a text rendering routine that renders text from a string buffer to a sprite texture as part of a custom implementation of sdl2.ext.System:

Minimal working example

Unfortunately, on my system (Mac OS X 10.11.6), I consistently get the following exception sometimes when using either SDL_CreateTexture (in Sprite.create()) or SDL_CreateTextureFromSurface (in main()).

Traceback (most recent call last):
  File "", line 207, in <module>
  File "", line 180, in main
    sprite = Sprite.create((0, 0), (100, 100), renderer=renderer)
  File "", line 138, in create
ValueError: NULL pointer access

I feel that I'm doing something wrong, but I cannot figure out the problem. I would be very grateful for your help!

Comments (4)

  1. Marcus von Appen repo owner

    Your check in line 133 in the gist is wrong. ctypes will return a LP_SDL_Texture pointer from the sdl2.render.SDL_CreateTexture() call in any case. This LP_* pointer however evaluates to true or false, depending on whether it contains a proper SDL_Texture or not, so you should change your check from

    if tex is None:
        raise SDLError()


    if not tex:
        raise SDLError()
  2. Log in to comment