Issue #59 invalid

sdl2.ext.TextureSpriteRenderSystem.renderer doesn't exist

Никола Вукосављевић
created an issue

The docs say that there's a renderer property in TextureSpriteRenderSystem, and some parts of pysdl2 think so too. It seems that it has been replaced with a _renderer at some point, but some pieces of code haven't been refactored to reflect that.

import ctypes
from sdl2 import *
import sdl2.ext


window = sdl2.ext.Window("Test", (640, 480))
render_system = sdl2.ext.TextureSpriteRenderSystem(window)
sprite_factory = sdl2.ext.SpriteFactory(renderer = render_system)
foo_bmp = sprite_factory.from_image(r"foo.bmp")
done = False
while not done:
    event = SDL_Event()
    while SDL_PollEvent(ctypes.byref(event)):
        if event.type == SDL_QUIT:
            done = True



The code above fails with:

Traceback (most recent call last):
  File "", line 11, in <module>
    foo_bmp = sprite_factory.from_image(r"foo.bmp")
  File "../../../sdl2/ext/", line 416, in from_image
    return self.from_surface(load_image(fname), True)
  File "../../../sdl2/ext/", line 426, in from_surface
    texture = render.SDL_CreateTextureFromSurface(renderer.renderer,
AttributeError: 'TextureSpriteRenderSystem' object has no attribute 'renderer'

Creating a SpriteFactory like this:

sprite_factory = sdl2.ext.SpriteFactory(renderer = render_system._renderer)

... works.

Comments (2)

  1. Marcus von Appen repo owner

    The SpriteFactory expects a Renderer, not a TextureSpriteRenderSystem:

    renderer = sdl2.ext.Renderer(window)
    factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)

    The sprite module documentation could be a bit more clear about that.

  2. Никола Вукосављевић reporter

    Ah, okay. Another point then: The docs say that TextureSpriteRenderSystem has renderer and rendertarget properties, but it doesn't:

    >>> import sdl2.ext
    >>> window = sdl2.ext.Window("Test", (400, 400))
    >>> render_system = sdl2.ext.TextureSpriteRenderSystem(window)
    >>> render_system.renderer
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'TextureSpriteRenderSystem' object has no attribute 'renderer'

    There's a _renderer, however:

    >>> dir(render_system)
    ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__',
    '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__',
    '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
    '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_renderer',
    '_sortfunc', 'componenttypes', 'process', 'render', 'sdlrenderer', 'sortfunc']
    >>> render_system._renderer
    <sdl2.ext.sprite.Renderer object at 0x00000000029CC208>
    >>> dir(render_system._renderer)
    ['__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',
    '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__',
    '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
    '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'blendmode',
    'clear', 'color', 'copy', 'draw_line', 'draw_point', 'draw_rect', 'fill', 'present', 'renderer',
    'rendertaget', 'rendertarget']
    >>> render_system._renderer.renderer
    <sdl2.render.LP_SDL_Renderer object at 0x00000000051975C8>
  3. Log in to comment