Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

surface must be a SDL_Surface when calling BitmapFont.render #180

Closed
namelivia opened this issue May 9, 2021 · 0 comments · Fixed by #181
Closed

surface must be a SDL_Surface when calling BitmapFont.render #180

namelivia opened this issue May 9, 2021 · 0 comments · Fixed by #181

Comments

@namelivia
Copy link
Contributor

namelivia commented May 9, 2021

First of all thanks to the maintainers for the effort.
I believe I've found a bug, I'm testing BitmapFont and I've been able to render text doing this:

font = sdl2.ext.BitmapFont(image, (size, size), mapping)
font.render_on(image, "TEXT", (size * len("TEXT"), 0))

so, I create the bitmap font and I'm able to render text using render_on.

However, I would like to create a new Sprite for my text, and by reading the documentation I think the way to do it would be just simply doing:

font = sdl2.ext.BitmapFont(image, (size, size), mapping)
font.render("TEXT")

But I get an exception stating surface must be a SDL_Surface. Is it a bug or am I misunderstanding anything?

I've done some debugging and tracking the origin of the error on these lines.

 sf = surface.SDL_CreateRGBSurface(0, tw, th, bpp, 0, 0, 0, 0)
        if not sf:
            raise SDLError()
        imgsurface = SoftwareSprite(sf, False)

Apparently even tho sf is an instance of: sdl2.surface.LP_SDL_Surface it seems not to be a valid first parameter for SoftwareSprite.

Also based mainly on this answer on stack overflow, it seems .contents is missing like:

 sf = surface.SDL_CreateRGBSurface(0, tw, th, bpp, 0, 0, 0, 0)
        if not sf:
            raise SDLError()
        imgsurface = SoftwareSprite(sf.contents, False)

I've tested this on a fork I've made and by doing so I've been able to get no exception and a SoftwareSprite instance back from the render method so I've opened a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant